3 ms·
I can tell you that at least in Python, for loops are not common for math. In fact, if I saw a C-style for loop counting indices, I’d defect it in any code I re
by theamk 7y ago
I can tell you that at least in Python, for loops are not common for math. In fact, if I saw a C-style for loop counting indices, I’d defect it in any code I review.
For simple things, you have list comprehensions and things like “sum”, while for complex things one should reach for numpy.
- misterdoubt 7y agoA 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.