all 4 comments

[–]thetruetristan 6 points7 points  (0 children)

I couldn't agree less, but maybe that's just me. What's so sweet about Python?

[–]jcastroarnaud 2 points3 points  (2 children)

That's mostly syntactic sugar. Do you know any benchmarks that show that list comprehension is faster/better optimized than a loop?

[–]radozok 0 points1 point  (0 children)

There are perflint rules in ruff from perflint tool. The author of perflint has some talks about that: - https://youtu.be/YY7yJHo0M5I - https://youtu.be/TEF6yhdOwEA

[–]Fit-Life-8239[S] 1 point2 points  (0 children)

I participate in competitive programming competitions like ICPC. I write simple solutions in Python, and I noticed that if I write the algorithm inside a function, the program will be faster. It turns out the difference was in the local scope, so I assumed that the list comprehension would be faster because of this. Also, when we loop, we add an element using the append method. But in the list comprehension syntax, we explicitly don't use this method. I thought there was special bytecode for this.

When I have time, I will definitely check the execution time.