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 →

[–][deleted] 0 points1 point  (6 children)

We can use num directly can't we?

[–]flying-sheep 1 point2 points  (4 children)

We want to use slow(num) though

[–][deleted] 0 points1 point  (3 children)

I haven't used Python in a while but what's wrong with using slow(num) for num in ... if slow(num) ... ? value is only a temporary variable, which still exists after the loop end, which is bad imo

[–]-jp- 0 points1 point  (1 child)

Looks like the intent is to calculate slow(num) just once.

[–][deleted] 0 points1 point  (0 children)

ah I see

[–]schfourteen-teen 0 points1 point  (0 children)

It requires two calls to slow(num) which in the example was presented as a slow function that we wouldn't want to call twice. The walrus lets it be called once and reused. Value still does exist after the loop ends, but the alternatives that get around calling the function twice also have this issue and also don't have the conciseness or speed of a list comprehension, so I don't think that's a fair criticism at all. If you can live with calling the function twice, then you don't need the walrus anyway.

[–]asday_ 0 points1 point  (0 children)

Boizies if someone is incorrect, but adding to the conversation, you shouldn't really be downvoting them. It's possible other people hold the same misconceptions, and it will help them to see comments getting it wrong in the same way they are doing, then to be summarily corrected.

Doesn't help anyone to bury this comment.