Re:Why Do Python Lists Multiply Oddly? Exploring the CPython...
by Joker_vD on Wednesday April 10, 2024 @06:22AM
(#39989061)
Well, Python is not Raku, so while it could be possible to make "[expr1, expr2, ..., exprN] * exprM" to mean "[*(expr1), *(expr2), ..., *(exprN) for _ in range(exprM)]", it would never happen.
Besides, that still doesn't help with the case of
x = function_that_returns_a_list()
x = x * 4
where there is no literal list expression.
It would be bad for this case, though. As confusing as the particular case of:
might be to people who haven't learned how it works, list multiplication doesn't just apply to single element lists, and is useful and usefully distinct from what people are suggesting the behavior should be for the operation based on this one case.