How to compare two lists with duplicated items in one list?
Posted
by
eladc
on Stack Overflow
See other posts from Stack Overflow
or by eladc
Published on 2012-10-20T16:58:27Z
Indexed on
2012/10/20
17:00 UTC
Read the original article
Hit count: 169
I need to compare list_a against many others. my problem starts when there's a duplicated item in the other lists (two k's in other_b).
my goal is to filter out all the lists with the same items (up to three matching items).
list_a = ['j','k','a','7']
other_b = ['k', 'j', 'k', 'q']
other_c = ['k','k','9','k']
>>>filter(lambda x: not x in list_a,other_b)
['q']
I need a way that would return ['k', 'q'], because 'k' appears only once in list_a.
comparing list_a and other_c with set() isn't good for my purpose since it will return only one element: k. while I need ['k','9','k']
I hope I was clear enough.
Thank you
© Stack Overflow or respective owner