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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com