[Solved] How to compare string value list inside list.Python


This is a job for sets

Convert your lists of lists to sets of tuples (you can’t have sets of lists, as sets can only contain hashable objects, which lists, as all built-in mutable objects, are not)

a = set(map(tuple, [['abc','Hello World'],['bcd','Hello Python']]))
b = set(map(tuple, [['abc','Hello World'],['bcd','Hello World'],['abc','Python World']]))

or create them directly as sets of tuples:

a = {('abc','Hello World'),('bcd','Hello Python')}
b = {('abc','Hello World'),('bcd','Hello World'),('abc','Python World')}

You can then easily and efficiently get your differences:

print(b - a)
# {('abc', 'Python World'), ('bcd', 'Hello World')}

print(a - b)
# {('bcd', 'Hello Python')}

or even the intersection

print(a & b)
# {('abc', 'Hello World')}

or the union:

print(a | b)
# {('abc', 'Python World'), ('bcd', 'Hello World'), ('abc', 'Hello World'), ('bcd', 'Hello Python')}

solved How to compare string value list inside list.Python