3 ms·
> That's the complaint, that [[]]4 is not shorthand for list comprehensions There are lots of reasons you would want items in a list repeated rather than havin
by dragonwriter 3y ago
> That's the complaint, that [[]]4 is not shorthand for list comprehensions
There are lots of reasons you would want items in a list repeated rather than having, essentially, the result of separate executions of the same constructor -- [] is just shorthand for list() -- so its good that [x()]4 is not shorthand for [x() for _ in range(4)]. Especially since that would mean it would have to be special-case sytax for list construction, and not a list operator that you could use on existing lists. The mildly annyoing edge case you need to learn about isn’t worth wiping out the whole broadly-useful language feature, or creating a great special-case inconsistency which would be more cognitive load to deal with, to eliminate.