Aug-21-2021, 04:44 AM
Greetings!
I'm trying to code in python for about a year now, had some success but I still do not understand how it iterates over a file.
for example, I want to print "Matched" and 'Unmatched" elements from two list_1.
Matched ++++++ ZPM911
Matched ++++++ ZPM912
Matched ++++++ ZPM919
Not Matched -- ZPM4555
Not Matched -- ZPM4556
Not Matched -- ZPM4557
When I remove "else" I get all "Matched " elements
I tried many different things but I could never get the output I want.
Thank you.
I'm trying to code in python for about a year now, had some success but I still do not understand how it iterates over a file.
for example, I want to print "Matched" and 'Unmatched" elements from two list_1.
list_1 =['ZPM911','ZPM1912','ZPM1919','ZPM4555','ZPM4556','ZPM4557'] list_2 = ['ZPM911,UP,DOWN','ZPM1912,UP,UP','ZPM1919,DOWN,DOWN'] for el in list_1 : el=el.strip() for ehl in list_2 : ehl=ehl.strip() sp0,*stuff = ehl.split(",") if el == sp0 : print(f" Matched ++++++ {el}") else : print(f" Not Matched -- {el}")I'd like to get output like this:
Matched ++++++ ZPM911
Matched ++++++ ZPM912
Matched ++++++ ZPM919
Not Matched -- ZPM4555
Not Matched -- ZPM4556
Not Matched -- ZPM4557
When I remove "else" I get all "Matched " elements
I tried many different things but I could never get the output I want.
Thank you.