How to make another list of the duplicate entries in existing list using python?
Question: I had a list like:

    
    
    l = [[(3,4)], [(3,7)], [(3,8)]]
    

I used the `chain()` function to flat the list, now I have a list like:

    
    
    l2 = [3,4,3,7,3,8]
    

I want to separate the duplicate items into another list:

    
    
    l3 = [3,3,3]
    l4 = [4,7,8]
    

I used the `set()` function, but it destroyed the duplicate items and resulted
in:

    
    
    l3 = [4,7,8]
    

but I want to obtain both of them separately


Answer: You'd have to do some kind of count. Using the [`collections.Counter()`
class](http://docs.python.org/2/library/collections.html#collections.Counter)
would make that easy:

    
    
    from collections import Counter
    counts = Counter(main_list)
    
    duplicate_list, unique_list = [], []
    for entry in main_list:
        if counts[entry] > 1:
            duplicate_list.append(entry)
        else:
            unique_list.append(entry)
    

`counts` is a multi-set or bag; a mapping of entry to it's count in
`main_list`. The above example preserves the ordering of `main_list`.

