4 ms·
A list comprehension is still a for loop. Using `for x in list` instead of `for i in len(list)` is a nice bit of sugar, but still a for loop. That said, high-p
by misterdoubt 7y ago
A list comprehension is still a for loop. Using `for x in list` instead of `for i in len(list)` is a nice bit of sugar, but still a for loop.
That said, high-performance Python does generally discourage the use of loops in favor of vectorised operations.
- deleted 7y ago[deleted]
- brudgers 7y agoI agree Python list comprehensions have loop semantics. But in fairness, a list comprehension in Python is an expression not a statement. Maybe it's best to think of Python's list comprehensions as loops with an implicit return.