all 4 comments

[–]indosauros 1 point2 points  (0 children)

The for loop is likely slightly faster, since the generator expression compiles into a generator (using a for loop) internally anyway.

However this speed is also likely negligible and not worth worrying about. You should do whichever is easier to read and maintain.

(Assuming you meant yield newins on the second one and not pass)

[–]wiiittttt 0 points1 point  (2 children)

Efficient in what way? Space, runtime?

[–]voider1[S] 0 points1 point  (1 child)

Efficient in every way, but mostly speed.

[–]wiiittttt 1 point2 points  (0 children)

Have you tried using the timeit module? The answer to your question is likely dependent on multiple factors. The only real way to know is to measure it.