This function takes an integer list (which your function must not modify) of unsorted values and returns a sorted list of all the duplicates in that first list. For example, duplicates([1, 3, 5, 7, 9, 5, 3, 5, 3])
would return [3, 5]
. If there are no duplicates, return an empty list.
Following is my current code, which doesn't work. How can I solve this problem?
def FindDuplicates(in_list):
unique = set(in_list)
for each in unique:
count = in_list.count(each)
if count > 1:
print count
return True
print []
return False