[Python-Dev] Re: accumulator display syntax

Skip Montanaro skip at pobox.com
Wed Oct 22 09:26:02 EDT 2003


>>>>> "David" == David Eppstein <eppstein at ics.uci.edu> writes:

 David> Currently, I am using expressions like
 David> pos2d = 
 David> dict([(s,(positions[s][0]+dx*positions[s][2],positions[s][1]+dy*positions[s
 David> ][2]))
 David> for s in positions])
which I would have written something like
 pos2d = dict([(s,(positions[s][0]+dx*positions[s][2],
 positions[s][1]+dy*positions[s][2]))
 for s in positions])
so that I could see the relationship between the two tuple elements.
 [ skipping the avoidance of listcomp syntactic sugar ]
 David> But with PEP 274, I could write
 David> pos2d = 
 David> {s:(positions[s][0]+dx*positions[s][2],positions[s][1]+dy*positions[s][2])
 David> for s in positions}
 David> Instead of five levels of nested parens+brackets, I would need
 David> only three, and each level would be a different type of paren or
 David> bracket, which I think together with the shorter overall length
 David> would contribute significantly to readability.
which I would still find unreadable and would recast in a more obvious (to
me) way as
 pos2d = {s: (positions[s][0]+dx*positions[s][2],
 positions[s][1]+dy*positions[s][2])
 for s in positions}
The extra characters required today are less of a problem if the expression
is laid out sensibly.
Skip


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /