A list comprehension will always produce a list object, in this case with the return values of all the t.join()
calls. Python thus produces as list with None
values of length len(threads)
for you. Python will never try to optimize away the list object creation.
Using map()
is also not any more efficient as you add additional stack pushes with the lambda
. Just stick with the explicit for
loop.
Really, for a series of thread joins there is no point in trying to micro optimize here.
You are hurting readability for a non-critical piece of code.
In other words, I entirely agree with the commenter. Do not use a list comprehension or map()
just for the side effects and saving yourself having to hit ENTER and create two lines of code.
Quoting the Zen of Python:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…