Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read this code?
#2
It is a List Comprehension
    items = [  # Here I need help I don't know what is going on here. We have some list(items = [])
        (o.value,)  # What is this?
        for i in book.active.iter_rows()  # Here we are going over sheet
        for o in i  # Here we are goking over lines
        if o.value
        and isinstance(o.value, str)  # Here we compare our words with cell data
        and search_string1.lower() in o.value.lower()
        and search_string2.lower()
        in o.value.lower()  # Could anybody describe this block of code in more detail
    ]  # Or write this piece of code for newbie language
This is the equivalent as normal for loops
    items = []
    for i in book.active.iter_rows():
        for o in i:
            if (
                o.value
                and isinstance(o.value, str)
                and search_string1.lower() in o.value.lower()
                and search_string2.lower() in o.value.lower()
            ):
                items.append((o.value,))

Edit: Included the tuple that I missed that @deanhystad reiterates below
Reply


Messages In This Thread
How to read this code? - by Jlyk - Aug-18-2021, 06:25 PM
RE: How to read this code? - by Yoriz - Aug-18-2021, 06:38 PM
RE: How to read this code? - by deanhystad - Aug-18-2021, 06:55 PM
RE: How to read this code? - by Jlyk - Aug-19-2021, 06:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python code to read second line from CSV files and create a master CSV file sh1704 1 2,433 Feb-13-2022, 07:13 PM
Last Post: menator01
  No output for the code to read emails avani9659 6 4,264 Aug-14-2018, 08:30 AM
Last Post: avani9659
  How to Make Python code execution pause and resume to create .csv and read values. Kashi 2 3,793 Jun-14-2018, 04:16 PM
Last Post: DeaD_EyE
  Cant find S3 Read or Write access from Python code tpc 0 2,393 Apr-19-2018, 04:00 AM
Last Post: tpc

Forum Jump:

User Panel Messages

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