[Python-Dev] Re: accumulator display syntax

David Eppstein eppstein at ics.uci.edu
Tue Oct 21 23:27:05 EDT 2003


On 10/21/03 11:17 PM -0400 Raymond Hettinger <python at rcn.com> wrote:
> -1
>
> Let's keep just one way to do it.
>
> That constuct saves a few characters just to get a little
> cuteness and another special case to remember and maintain.
>
> Once you have iterator expressions, you've already gotten 99% of
> the benefits of PEP 274.

Currently, I am using expressions like

	pos2d = 
dict([(s,(positions[s][0]+dx*positions[s][2],positions[s][1]+dy*positions[s
][2]))
               for s in positions])

Once I have iterator expressions, I can simplify it by dropping a whole two 
characters (the brackets) and get an unimportant time savings.  But with 
PEP 274, I could write

	pos2d = 
{s:(positions[s][0]+dx*positions[s][2],positions[s][1]+dy*positions[s][2])
          for s in positions}

Instead of five levels of nested parens+brackets, I would need only three, 
and each level would be a different type of paren or bracket, which I think 
together with the shorter overall length would contribute significantly to 
readability.
-- 
David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science




More information about the Python-Dev mailing list