This five line code will sort-out the duplicate and non duplicate elements from the given list of number
input = [10,20,30,11,10]
duplicate_list, non_duplicate_list = [],[]
for el in input:
duplicate_list.append(el) if(el in non_duplicate_list) else non_duplicate_list.append(el)
print(duplicate_list, non_duplicate_list)
and the output is
([10], [10, 20, 30, 11])
Thanks to https://simpleprogrammer.com/programming-interview-questions/ to post the question
Top comments (0)