List comprehensions' ugliness (Was: Re: How to explain exactly what "def" does?)
jerf at compy.attbi.com
jerf at compy.attbi.com
Thu Feb 6 01:50:42 EST 2003
On Thu, 06 Feb 2003 06:26:31 +0000, jer wrote:
> maxA = max([x.a for x in l])
> allBs = [x.b for x in l]
> maxAll = [max(x.a, x.b, x.c) for x in l]
> oddSums = [x.a+x.b+x.c for x in l if x.a % 2]
> stupidSerialization = "\n".join([','.join(x.a, x.b, x.c) for x in l])
It seems Pan "helpfully" decided to re-wrap that series for me. The above
shows the five functions that were supposed to be shown. Plus I'd like to
add
-----
a = "some serialized string as in stupidSerialization"
structs = [SomeStruct(*(x.split(",")) for x in a.split("\n")]
-----
The only thing that really puts that last line a little over the edge is
the use of the semi-obscure (but kick-ass) asterisk syntax, but for me it
still says nicely in one line what would take a lot more in any other form.
More information about the Python-list
mailing list