Python Forum
Still do not get how Python iterates over a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Still do not get how Python iterates over a file
#1
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.
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.
Reply


Messages In This Thread
Still do not get how Python iterates over a file - by tester_V - Aug-21-2021, 04:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Do not get how Python iterates over a file tester_V 12 1,830 Jan-29-2023, 01:49 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020