how to predict unique list in lists?
Question: This is list of tile placements. Each integer stands for an id of a tile. Each
time an integer is added to a new list it means that a new tile is placed.
When a tile is removed, the last integer is removed from a new list. I want
that every time a tile is placed the list to be unique. A list dont have to be
unique, when a tile is removed. The code is placing these tiles in a for loop.
So for this example, the last list of the lists is wrong, because it wasn't
unique when a tile was placed. Is there a way to exclude numbers which will
make the new list not unique. So for this example is there a way to exclude
the id 18, before it adds to the list.

I know this is a very vague question, but I am new to python and can't make
the code of this assignment easier. I hope someone could help me with this
vague question

    
    
        [[1, 2, 3, 13, 4, 5, 6, 7, 17], 
        [1, 2, 3, 13, 4, 5, 6, 7, 17, 8], 
        [1, 2, 3, 13, 4, 5, 6, 7, 17, 8, 15],
        [1, 2, 3, 13, 4, 5, 6, 7, 17, 8, 15, 9],
        [1, 2, 3, 13, 4, 5, 6, 7, 17, 8, 15, 9, 10],
        [1, 2, 3, 13, 4, 5, 6, 7, 17, 8, 15, 9, 10, 18], 
        [1, 2, 3, 13, 4, 5, 6, 7, 17, 8, 15, 9, 11], 
        [1, 2, 3, 13, 4, 5, 6, 7, 17, 8, 15, 9, 11, 18], 
        [1, 2, 3, 13, 4, 5, 6, 7, 17, 8, 15, 9, 10], 
        [1, 2, 3, 13, 4, 5, 6, 7, 17, 8, 15, 9, 10, 18]] 
    

The lists must be in this order. So for example i have had these lists:

    
    
    [[1, 2, 3, 13, 4, 5, 6, 7, 17], 
    [1, 2, 3, 13, 4, 5, 6, 7], 
    [1, 2, 3, 13, 4, 5, 6, 7, 8],
    [1, 2, 3, 13, 4, 5, 6, 7],
    [1, 2, 3, 13, 4, 5, 6, 7, 19],
    [1, 2, 3, 13, 4, 5, 6, 7]]
    

I want to exlude the ids 17,8,19

So for [1, 2, 3, 13, 4, 5, 6, 7] the output must look like this ( id ont care
if the output is a list or integers)

    
    
    [17,8,19]
    

But when i have this list [1, 2, 3, 13, 4, 5, 6] in lists

    
    
    [[1, 2, 3, 13, 4, 5, 6, 7, 17], 
    [1, 2, 3, 13, 4, 5, 6], 
    [1, 2, 3, 13, 4, 5, 6, 7, 8],
    [1, 2, 3, 13, 4, 5, 6, 7],
    [1, 2, 3, 13, 4, 5, 6, 7, 19],
    [1, 2, 3, 13, 4, 5, 6, 7]]
    

The output is this:

    
    
    [7]
    

I hope this will make it more clear.


Answer: I tried with `itertools` and `collections`\- pass a list, a list element index
and to be added value to the `adder function` if uniquness is kept the adder
will add that passed value otherwise return intact list.`compare_func` return
`TRUE` if list is unique using `all`.

    
    
    import collections,itertools
    compare_func = lambda x, y: collections.Counter(x) != collections.Counter(y)
    lst = [[1, 2, 3],[1, 2, 3,4]] 
    
    def adder(mylist,indx,val):
        mylist[indx].append(val)   
        if  all([compare_func(*i) for i in list(itertools.combinations(lst,2))]):
            print "Added item"
        else:
            print "Did not add item"
            mylist[indx].pop()
        return mylist
    

Now run `print adder(lst,0,4)`

Output-

    
    
    Did not add item
    [[1, 2, 3], [1, 2, 3, 4]]
    

But if run

`print adder(lst,1,4)`

Output-

    
    
    Added item
    [[1, 2, 3], [1, 2, 3, 4, 4]]
    

* * *

## EDIT

After OP cleared question i added this portion-

Try using `set` as below-

    
    
    import collections,itertools
    
    data = [[1, 2, 3, 13, 4, 5, 6, 7, 17], 
            [1, 2, 3, 13, 4, 5, 6, 7], 
            [1, 2, 3, 13, 4, 5, 6, 7, 8],
            [1, 2, 3, 13, 4, 5, 6, 7],
            [1, 2, 3, 13, 4, 5, 6, 7, 19],
            [1, 2, 3, 13, 4, 5, 6, 7]]
    
    
    interscntion = set.intersection(*map(set,data))
    
    d = collections.Counter([i for j in data for i in j if i not in list(interscntion)])
    if len(set(it[1] for it in d.most_common()))>1:
        print [max(d.most_common(),key=lambda x:x[1])[0]]
    else:
        print [j[0] for j in d.most_common()]
    

Output-

    
    
    [8, 17, 19]
    

