Switch statements again
A. Lloyd Flanagan
alloydflanagan at attbi.com
Thu Jan 16 10:24:44 EST 2003
Jack Diederich <jack at performancedrivers.com> wrote in message news:<mailman.1042672181.22990.python-list at python.org>...
> using a list comprehension or zip(). Comprehensions always
> hurt readability (ALWAYS), and we don't need the speedup
> here so we do it explicitly.
Personally, I find list comprehensions to be both very readable and
compact. Maybe it's a matter of how familiar you are with them.
x = [a[3].someMethod() for a in some_list if a[2] == y]
seems clearer than:
x = []
for a in some_list:
if a[2] == y:
x += a[3].someMethod()
after all, a list comprehension is less general than a for-loop, so
you know more about what it does before you read it.
More information about the Python-list
mailing list