In order for my code to be efficient, loops need to be terminated prematurely to prevent unnecessary iterations. I know that list comprehension is fast that the 'for' statement, but I'm having trouble finding a suitable way to break them. Here's what I've come up with
try:
[x if x < 5 else 1/0 for x in range(5)]
except:
pass
[0, 1, 2, 3, 4]
I'm just using an exception to break it.