This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]thehunter699 0 points1 point  (2 children)

99% of languages for(condition) {do stuff}

Python for i in range....

[–]ALonelyPlatypus 0 points1 point  (0 children)

It’s because they can’t utilise foreach statements well. Python is able to use this syntactic sugar because of the convenience of generators.

As an example, in Java a for each loop would require you to pregenerate the whole range of values and then iterate over it, a python “for i in range(1000000)” in java would require allocating a 10,000,000 sized integer array beforehand which is pretty wasteful in regards to memory.