4 ms·
You can use a generator expression: all_matches = ( (r, c) for r, row in enumerate(table.rows) for c, cell in enumerate(row) if search_query.
by progval 4y ago
You can use a generator expression:
all_matches = (
(r, c)
for r, row in enumerate(table.rows)
for c, cell in enumerate(row)
if search_query.matches(cell.value)
)
found = next(all_matches, None)
if found:
logger.log("Found cell: {}".format(found))
return found
It is lazy, so it stops as soon as the first match is found.
- dataflow 4y agoThis doesn't generalize well. Add a statement or something in the loop and it clashes with this.