A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-October/039283.html below:

[Python-Dev] Re: accumulator display syntax

[Python-Dev] Re: accumulator display syntaxSkip 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4