by maxcoder4 · 2y ago · 0 comments
The first code is equivalent to:
list_multiply([x], 4)
(the function is actually called list.__mul__, but that's an unimportant detail). The latter is a syntax sugar for:
out = [] for _ in range(4): out.append(x)
(actually a bit more complex, but close enough).
When you understand it, the behavior is obvious in both cases.
No comments yet.