Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81387

Re: Comprehension with two variables - explanation needed

References <mailman.16184.1416754678.18130.python-list@python.org> <d1194d28-e9ed-4bd3-86e9-899e13a17097@googlegroups.com> <002501d00733$6995dce0$3cc196a0$@gmail.com> <mailman.16191.1416757555.18130.python-list@python.org> <roy-B11F64.10563923112014@news.panix.com>
Date 2014-11-23 10:45 -0600
Subject Re: Comprehension with two variables - explanation needed
From Skip Montanaro <skip.montanaro@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16197.1416761116.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Nov 23, 2014 at 9:57 AM, Roy Smith <roy@panix.com> wrote:
>
> If it was complicated enough that you needed to loopify it to
> understand what it's doing, have pity on the next person who has to
> maintain your code and leave it as a loop

Well, sure. I was mostly trying to give Ivan a path out of the weeds.
Poking through the code I'm involved with at work, using a crude
measuring stick (a couple regular expressions) I found over 1400 one
line list comprehensions, those which matched this regular expression:

\[.* for .*\]

OTOH, I only found 14 with two "for" keywords:

\[.* for .* for .*\]

(There may well have been more nested loop list comprehensions, simply
because it's hard to cram the full listcomp into 80 columns, my
self-imposed column limit.)

In my experience, list comprehensions rapidly get unwieldy once you
get to nesting them. I generally unravel such items into a nested set
of for loops.

Skip

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Comprehension with two variables - explanation needed "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-11-23 16:56 +0200
  Re: Comprehension with two variables - explanation needed Rustom Mody <rustompmody@gmail.com> - 2014-11-23 07:09 -0800
    RE: Comprehension with two variables - explanation needed "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-11-23 17:37 +0200
    Re: Comprehension with two variables - explanation needed Chris Angelico <rosuav@gmail.com> - 2014-11-24 02:42 +1100
    RE: Comprehension with two variables - explanation needed Skip Montanaro <skip.montanaro@gmail.com> - 2014-11-23 09:45 -0600
      Re: Comprehension with two variables - explanation needed Roy Smith <roy@panix.com> - 2014-11-23 10:57 -0500
        Re: Comprehension with two variables - explanation needed Rustom Mody <rustompmody@gmail.com> - 2014-11-23 08:45 -0800
          Re: Comprehension with two variables - explanation needed Rustom Mody <rustompmody@gmail.com> - 2014-11-23 09:17 -0800
          RE: Comprehension with two variables - explanation needed "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-11-23 19:27 +0200
          Re: Comprehension with two variables - explanation needed Steven D'Aprano <steve@pearwood.info> - 2014-11-24 04:42 +0000
            Re: Comprehension with two variables - explanation needed Chris Angelico <rosuav@gmail.com> - 2014-11-24 15:51 +1100
              Re: Comprehension with two variables - explanation needed Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-25 09:20 +1100
            Re: Comprehension with two variables - explanation needed Rustom Mody <rustompmody@gmail.com> - 2014-11-23 22:47 -0800
            Re: Comprehension with two variables - explanation needed Dan Stromberg <drsalists@gmail.com> - 2014-11-24 16:42 -0800
        Re: Comprehension with two variables - explanation needed Skip Montanaro <skip.montanaro@gmail.com> - 2014-11-23 10:45 -0600
        Re: Comprehension with two variables - explanation needed Roy Smith <roy@panix.com> - 2014-11-23 12:08 -0500
        Re: Comprehension with two variables - explanation needed Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2014-11-23 17:46 +0000

csiph-web