Home python How to compare two list?

How to compare two list? [Duplicate]

Author

Date

Category

Sorry for the stupid question.

g = ['mon1-1', 'mon2-2', 'mon3-3']
G2 = ['MON1-1', 'MON2-2']

How to compare G from G2 (two list), if the value does not find, output only what I did not find, and it will be a variable MON3-3.


Answer 1, Authority 100%

If the speed is not critical, then it is possible:

for e in g:
  IF NOT E IN G2:
    Print E.

This is how you can get a list of all the necessary items:

g = [e for e in g iF not e in g2]

quickly will be used by sets:

ss = set (g) - set (G2)

But this method works only if the multiplicity of items is not important.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions