3 ms·
After a quick IRC discussion; you wrote it wrong :D! Using hy --spy so you can see the equivalent python code: => (list-comp (, x y) [x (range 5) y (rang
by Foxboron 12y ago
After a quick IRC discussion; you wrote it wrong :D!
Using hy --spy so you can see the equivalent python code:
=> (list-comp (, x y) [x (range 5) y (range 5)] (> 2 x))
from hy.core.language import range
[(x, y) for x in range(5) for y in range(5) if (2 > x)]
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 1) .....]
Can submit a PR and fix the docs so this is better displayed!
- omaranto 12y agoDoesn't what you wrote work in a different, slower, way? I had in mind something analogous to r = [] for x in range(5): if 2>x: for y in range(5): r.append((x,y)) I think what you wrote probably does: r = [] for x in range(5): for y in range(5): if 2>x: r.append((x,y)) The first loop completely skips looping over y if the condition on x fails, the second loop repeatedly tests x.
- Foxboron 12y agoHurm yes indeed. Interesting problem. I'll copypasta this and fix up an issue! Nice catch!