[Python-ideas] Fwd: Fwd: Fwd: unpacking generalisations for list comprehension
Sven R. Kunze
srkunze at mail.de
Thu Oct 20 14:21:03 EDT 2016
On 18.10.2016 08:23, Greg Ewing wrote:
> If it were a namedtuple, for example, you could write
>
> [*t for t in fulltext_tuples if t.language == 'english']
>
> or
>
> [x for t in fulltext_tuples if t.language == 'english' for x in t]
>
> The latter is a bit unsatisfying, because we are having to
> make up an arbitrary name 'x' to stand for an element of t.
> Even though the two elements of t have quite different roles,
> we can't use names that reflect those roles.
It's an intriguing idea to use namedtuples but in this case one should
not over-engineer.
What I dislike most are the names of "fulltext_tuple", "x", "t". If I
were to use it, I think my coworkers would tar and feather me. ;) This
is one of the cases where it makes absolutely no sense to invent
artificial names for the sake of naming. I can name a lot of (internal)
examples where we tried really hard at inventing named concepts which
make absolutely no sense half a year later even to those who invented
them. Repeatedly, in the same part of the code.
Each newly named concept introduces another indirection. Thus, we always
need to find a middle ground between naming and using language features,
so I (personally) would be grateful for this particular feature. :)
> Because of that, to my eyes the version with * makes it easier
> to see what is going on.
That's a very nice phrase: "makes it easier to see what is going on". I
need to remember that.
Cheers,
Sven
More information about the Python-ideas
mailing list