Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read this code?
#3
For some reason the code builds a list of tuples. The expanded code would be:
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,))
And to answer the other question, (o.value,) makes a tuple that contains o.value.
a = 5
b = (a,)
c = tuple([a])
d = (a)
print(a, b, c, d)
Output:
5 (5,) (5,) 5
Notice that the trailing comma is required. In "b = (a,)" the parenthesis tell Python to make a Tuple. Without the comma, "d = (a)", the parenthesis are interpreted as a grouping operator. Do everything inside the parenthesis first as in x = (1 + 2) * 3 tells Python to add 1 and 2 before multiplying by 3.
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