python - how to predict unique list in lists? -


this list of tile placements. each integer stands id of tile. each time integer added new list means new tile placed. when tile removed, last integer removed new list. want every time tile placed list unique. list dont have unique, when tile removed. code placing these tiles in loop. example, last list of lists wrong, because wasn't unique when tile placed. there way exclude numbers make new list not unique. example there way exclude id 18, before adds list.

i know vague question, new python , can't make code of assignment easier. hope me 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 in order. example 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 exlude ids 17,8,19

so [1, 2, 3, 13, 4, 5, 6, 7] output must ( id ont care if output list or integers)

[17,8,19] 

but when have 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 this:

[7] 

i hope make more clear.

i tried itertools , collections- pass list, list element index , added value adder function if uniquness kept adder add passed value otherwise return intact list.compare_func return true if list 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) 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 added portion-

try using set 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 j in data in j if not in list(interscntion)]) if len(set(it[1] in d.most_common()))>1:     print [max(d.most_common(),key=lambda x:x[1])[0]] else:     print [j[0] j in d.most_common()] 

output-

[8, 17, 19] 

Comments