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

后端 未结 8 1798
情深已故
情深已故 2020-12-01 03:47

What is the easiest way to compare the 2 lists/sets and output the differences? Are there any built in functions that will help me compare nested lists/sets?

Inputs:

8条回答
  •  无人及你
    2020-12-01 04:20

    >>> First_list = [['Test.doc', '1a1a1a', '1111'], ['Test2.doc', '2b2b2b', '2222'], ['Test3.doc', '3c3c3c', '3333']] 
    >>> Secnd_list = [['Test.doc', '1a1a1a', '1111'], ['Test2.doc', '2b2b2b', '2222'], ['Test3.doc', '3c3c3c', '3333'], ['Test4.doc', '4d4d4d', '4444']] 
    
    
    >>> z = [tuple(y) for y in First_list]
    >>> z
    [('Test.doc', '1a1a1a', '1111'), ('Test2.doc', '2b2b2b', '2222'), ('Test3.doc', '3c3c3c', '3333')]
    >>> x = [tuple(y) for y in Secnd_list]
    >>> x
    [('Test.doc', '1a1a1a', '1111'), ('Test2.doc', '2b2b2b', '2222'), ('Test3.doc', '3c3c3c', '3333'), ('Test4.doc', '4d4d4d', '4444')]
    
    
    >>> set(x) - set(z)
    set([('Test4.doc', '4d4d4d', '4444')])
    

提交回复
热议问题