100+
P: 440

Hi,
I have two lists,i have to get the remaining list elements other than common elements.
I/P :
l1 = [1,2,3,4]
l2=[2,3]
O/P
From l1 & l2.I have to get the uncommon elements
[1,4]
Thanks
PSB
 
Share this Question
Expert 5K+
P: 6,596

Hi,
I have two lists,i have to get the remaining list elements other than common elements.
I/P :
l1 = [1,2,3,4]
l2=[2,3]
O/P
From l1 & l2.I have to get the uncommon elements
[1,4]
Thanks
PSB
With sets you can do union, intersection, ect. Or:
>>> l1 = [1, 2, 3, 4]
>>> l2 = [2, 3]
>>> list(set(l1)  set(l2))
[1, 4]
>>>
  Expert 100+
P: 511

you should be able to understand how to use sets by now, since barton has showed you how here   Expert Mod 2.5K+
P: 2,851

If you do not want to use sets, you could do this:  >>> lst1 = [1,2,3,4,5,6,7,8,9,0,11,12,13]

>>> lst2 = [5,6,7,12,45,67,89,99]

>>> [i for i in lst1+lst2 if i not in lst1 or i not in lst2]

[1, 2, 3, 4, 8, 9, 0, 11, 13, 45, 67, 89, 99]

>>>
    Question stats  viewed: 20497
 replies: 3
 date asked: May 20 '07
