Skip to content
Advertisement

Are these two for loops the same efficient in python?

JavaScript

My question is for the 2nd for loop, is ‘list(d)’ executed multiple times, or only once? If it is executed only once, it’s more compact.

Advertisement

Answer

Here’s a simple test:

JavaScript

And the output is

JavaScript

It seems that list(d) is only called once, so there’s no performance difference.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement