I would like to give some feedback about ...
From: http://www.checkio.org/mission/non-unique-elements/solve/
HTTP\_USER\_AGENT:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
My Code:
#Your optional code here
#You can import some modules or create additional functions
def checkio(data):
#Your code here
#It's main function. Don't remove this function
#It's used for auto-testing and must return a result for check.
#My Solution begins
#First, create a new list that is a clone for the original
OrphanBlack=data.copy()
#Second, get the lenght of this set and find the last possible index
LastIndex=len (OrphanBlack)
#Third, create an index counter and start with zero
Index=0
print ("STARTING .........")
while Index in range (LastIndex):
Bug=OrphanBlack[Index]
DeadBug=OrphanBlack.count(Bug)
LoopNumber=Index
print ("List size is", LastIndex , "elements")
print ("Loop number", LoopNumber)
print ("Counting ", DeadBug, " times in ", Index, " position the number", Bug)
if DeadBug==1:
print ("Find the Bug!", OrphanBlack[Index])
del OrphanBlack [Index]
LastIndex=len (OrphanBlack)
print ("Restarting the counting")
print ("|||||||||||||||||||||||||")
Index=0
print ("Newsize of list is ", LastIndex)
if LastIndex==1:
OrphanBlack.clear()
Index=Index+1
data=OrphanBlack
print ("Result", data)
return data
#Some hints
#You can use list.count(element) method for counting.
#Create new list with non-unique elements
#Loop over original list
if __name__ == "__main__":
#These "asserts" using only for self-checking and not necessary for auto-testing
assert isinstance(checkio([1]), list), "The result must be a list"
assert checkio([1, 2, 3, 1, 3]) == [1, 3, 1, 3], "1st example"
assert checkio([1, 2, 3, 4, 5]) == [], "2nd example"
assert checkio([5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5], "3rd example"
assert checkio([10, 9, 10, 10, 9, 8]) == [10, 9, 10, 10, 9], "4th example"
Created at: 2014/07/10 19:43; Updated at: 2014/07/10 19:43