I have a list of objects, that I need to iterate through and add all duplicates or more to another list and return that list.
list_in = ["a", "b", "b", "c", "d", "d", "d", "e"]
list_out = ["b", "b", "d", "d", "d"]
What is the most pythonic way to achieve this, I was trying using indexes, but was not successful.
Here is my first draft of this issue, but this adds up in no way. How could this be implemented using indexes ?
def find_dups(a):
for i, item in enumerate(a)+1:
j = i
for j, item_b in enumerate(a)+1:
if a[i] == a[j+1]:
list_dups.append(a[i])
list_dups.append(a[j+1])
#break
#print a[i], a[i+1]
return list_dup