[Python-Dev] listcomps vs. for loops
Guido van Rossum
guido at python.org
Wed Oct 22 14:45:47 EDT 2003
More information about the Python-Dev mailing list
Wed Oct 22 14:45:47 EDT 2003
- Previous message: [Python-Dev] listcomps vs. for loops
- Next message: [Python-Dev] listcomps vs. for loops
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> sum(len(line) for line in file if not line.startswith("#") while
> line.strip())
>
> looks simple than
>
> sum(itertools.takewhile(lambda l: l.strip(), len(line) for line in file
> if not line.startswith("#"))
I think both are much harder to read and understand than
n = 0
for line in file:
if not line.strip():
break
if not line.startwith("#"):
n += len(line)
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] listcomps vs. for loops
- Next message: [Python-Dev] listcomps vs. for loops
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list