How do I find the duplicates in a list and create another list with them?
To remove duplicates use set(a). To print duplicates, something like: Note that Counter is not particularly efficient (timings) and probably overkill here. set will perform better. This code computes a list of unique elements in the source order: or, more concisely: I don’t recommend the latter style, because it is not obvious what not seen.add(x) is doing (the set add() method always returns None, hence … Read more