2 ms·
In that case a flatmap does the job fine[0]. In fact you don't even need a flatmap: found = next(( (r, c) for r, row in enumerate(table.row
by masklinn 4y ago
In that case a flatmap does the job fine[0]. In fact you don't even need a flatmap:
found = next((
(r, c)
for r, row in enumerate(table.rows):
for c, cell in enumerate(row):
if search_query.matches(cell.value)
), None)
Or just return at the location where you found a match. That way you can also provide a better error message in the failure case.
[0] well map + itertools.concat, IIRC the stdlib doesn't have a flatmap per-se, though more_itertools probably does.