Aug-18-2021, 06:55 PM
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.