[Python-Dev] PEP-xxx: Unification of for statement and list-compsyntax (original) (raw)

Terry Reedy tjreedy at udel.edu
Sun May 21 20:31:11 CEST 2006


"Heiko Wundram" <me+python-dev at modelnine.org> wrote in message news:200605211710.51720.me+python-dev at modelnine.org...

As I've noticed that I find myself typing the latter quite often in code I write, it would only be sensible to add the corresponding syntax for the for statement:

for node in tree if node.haschildren(): as syntactic sugar for: for node in tree: if not node.haschildren(): continue

Isn't this the same as

  for node in tree:
      if  node.haschildren():
          <do something with node>

so that all you would save is ':\n' and the extra indents?

tjr



More information about the Python-Dev mailing list