extend for loop syntax with if expr like listcomp&genexp ?

Paul Rubin http
Thu Jul 14 03:19:24 EDT 2005


Terry Hancock <hancock at anansispaceworks.com> writes:
> But of course that's not equivalent.  It's hard to imagine a
> use case for an enumerated loop when the object being
> iterated over is anonymous (will be lost as soon as the loop exits).

Huh?  Not at all.

  print 'List of Python fans:'
  for i,x in enumerate([p for p in people if p.favorite_language == 'Python']):
    print '%d. %s'% (i, x.name)



More information about the Python-list mailing list