On Mon, Oct 17, 2016 at 7:50 PM, Random832 firstname.lastname@example.org wrote:
On Mon, Oct 17, 2016, at 22:17, David Mertz wrote:
[*range(x) for x in range(4)]
As Paul or someone pointed out, that's a fairly odd thing to do.
I agree with the specific example of it being an odd thing to do with range, it was just an attempt to illustrate with a concrete example.
It's also easy to construct examples where the hypothetical * syntax can't handle a requirement. E.g. flatten() with levels>1 (yes, of course you can find some way to nest more loops or more comprehensions-within-comprehensions to make it work in some way that still uses the * by force).
I feel like I should be honest about something else - I'm always a
little bit confused by the ordering for comprehensions involving multiple clauses.
Me too! I get the order of nested loops in comprehensions wrong about 25% of the time. Then it's a NameError, and I fix it.
This is a lot of why I like a utility function like `flatten()` that is pretty much self-documenting. Perhaps a couple other itertools helpers would be nice.