How to compare 2 lists of unicode ? in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to compare 2 lists of unicode ? in python

Hello everyone , How can i compare 2 lists of unicode in python? such as : mylist=[u'marc',u'max,u'chan',u'jackie'] mysecondlist=[u'marc,u'china',u'france'] thank you for helping me !

29th Mar 2021, 8:03 AM
Maximilien
Maximilien  - avatar
2 Answers
+ 3
There are many ways to compare lists of unicode-encoded strings in Python. You can compare for equality like this: mylist=[u'marc',u'max',u'chan',u'jackie'] mysecondlist=[u'marc',u'max', u'chan',u'jackie'] print(mylist == mysecondlist) # prints True indicating they're equal. You could convert to sets if you want to see what elements are in one set and not in the other like this: mylist=[u'marc',u'max',u'chan',u'jackie'] mysecondlist=[u'marc',u'china',u'france'] print(list(set(mylist) - set(mysecondlist))) # prints ['max', 'jackie', 'chan']. marc is in mysecondlist so it was not printed.
29th Mar 2021, 9:25 AM
Josh Greig
Josh Greig - avatar
29th Mar 2021, 10:03 AM
Maximilien
Maximilien  - avatar