Get difference between two lists

前端 未结 27 2828
傲寒
傲寒 2020-11-21 11:36

I have two lists in Python, like these:

temp1 = [\'One\', \'Two\', \'Three\', \'Four\']
temp2 = [\'One\', \'Two\']

I need to create a third

27条回答
  •  心在旅途
    2020-11-21 11:44

    If you run into TypeError: unhashable type: 'list' you need to turn lists or sets into tuples, e.g.

    set(map(tuple, list_of_lists1)).symmetric_difference(set(map(tuple, list_of_lists2)))
    

    See also How to compare a list of lists/sets in python?

提交回复
热议问题