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
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