[Chicago] Factoring fun with functions in Python

Dan Krol orblivion at gmail.com
Wed Nov 14 20:34:02 CET 2012

I took that to mean something different:



for x in [1,2,3]:
    for y in [4,5,6]:
        print x, y


from itertools import product

for x, y in product([1,2,3], [4,5,6]):
    print x, y


This sort of "flatness" is inherently easier to read than the radical
function splitting because it's sequential. It describes a narrative.
Instead of "for each of these, then again for each of those, do this",
which is harder to follow, you say "for each combination of these and
those, do this".

What you're eliminating with the splitting into functions isn't what
would I thought was referred to as "nested". Your original code was
only a little nested. You eliminated some nesting but you mostly
eliminated length.

Though maybe I've just been following a false Zen.

On Wed, Nov 14, 2012 at 11:23 AM, Garrett Smith <g at rre.tt> wrote:
> On Wed, Nov 14, 2012 at 12:24 PM, Dan Krol <orblivion at gmail.com> wrote:
>> There must be something to be said for hierarchy.
> Indeed:
> python -c "import this" | grep nested
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago

More information about the Chicago mailing list