3 ms·
Anyone else having trouble parsing this list comprehension ? e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in NWORDS
by tgflynn 16y ago
Anyone else having trouble parsing this list comprehension ?
e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in NWORDS
- marcinw 16y agoIn a traditional for loop fashion: def known_edits2(word): L = [] for e1 in edits1(word): for e2 in edits1(e1): if e2 in NWORDS: L.append(e2) return set(L)
- tgflynn 16y agoThanks for the clarification. I didn't realize that list comprehensions mapped so directly to nested loops, I was particularly confused by the variable name scoping rules.
- deleted 16y ago[deleted]
- cema 16y agoThe double "comprehension" loop is like a double nested "regular" loop here.