аватар question@mail.ru · 01.01.1970 03:00

The difference in lists in Python [duplicate]

(4 & nbsp; answer)
closed 7 years Back .

There are three lists: list1 , list2 and list3 . & gt; List2 (according to the number of elements), and list3 is empty.

It is also known that the first elements of list1 and list2 are the same (for example, list1 = [Vasya, Petya, Masha, Masha, Masha, Masha, Masha Sasha] , and List2 = [Vasya, Petya] ).

Task: fill List3 The difference of the first and second lists, i.e. On the above example list3 = [Masha, Sasha] .

аватар answer@mail.ru · 01.01.1970 03:00

offhand (because the output elements will be unique, i.e. without repetitions) + it does not matter what indices of the elements that are on both lists:

  u'vasya ',  ,  u'mash' ,  u'sasha '] list2 = [ u'vasya ', ] list3 =  list  ( set  (list2))   print  list3  [ u'mash ' u'sasha' ]                                       

Latest

Similar