A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2006-May/065109.html below:

Unification of for statement and list-comp syntax

[Python-Dev] PEP-xxx: Unification of for statement and list-comp syntax [Python-Dev] PEP-xxx: Unification of for statement and list-comp syntaxGreg Ewing greg.ewing at canterbury.ac.nz
Mon May 22 08:44:47 CEST 2006
Heiko Wundram wrote:
> Am Montag 22 Mai 2006 01:59 schrieb Josiah Carlson:
> > Not everyone finds list comprehensions easy to read.
> 
> Why has Python added list-comprehensions, then? (or at least, why has Python 
> added the 'if'-expression to list-comprehensions if they're hard to read?

LCs are useful because they're expressions rather than statements.
Being expressions, they need if-clauses in order to be able to
conditionally include items in the list. LCs with if-clauses don't
*have* to be hard to read; you just need to lay them out on separate
lines, as you would do when writing nested statements.

With a for-statement, there is no need for if-clauses, since you
can use a nested if-statement to get the same effect. The only
possible reason for wanting an if-clause would be so that you
can write it on the same line, which reduces readability for no
corresponding benefit.

--
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4