[ad_1]
PYTHON PROGRAMMING
Even fairly sophisticated Python comprehensions might be extra readable than the corresponding for loops.
Python comprehensions — together with listing, dictionary and set comprehensions in addition to generator expressions — represent a robust Python syntactic sugar. You may examine them within the following articles:
Python comprehensions have two nice benefits when in comparison with the corresponding for
loops: they’re sooner and they are often rather more readable.
Word the phrase “might be rather more readable.” Certainly, they aren’t at all times extra readable. This begs the next query: When are they?
It relies on you. It’s you — the developer — who makes a Python comprehension readable. Sloppy implementation can destroy a comprehension’s readability, although the identical might be stated about for
loops.
Comprehensions in Python had been designed to be learn in a really comparable manner that you just learn an English sentence: You may learn a comprehension from left to proper (or from prime to backside, if it takes a number of strains) similar to you learn an English sentence from left to proper.
Many say you shouldn’t use advanced comprehensions as a result of they’re tough to learn and comprehend. On this article, we’ll talk about this well-known precept — if not a fable. Sadly, many individuals pressure this precept by excessively avoiding using Python comprehensions in conditions the place they may very well be used with success.
You may learn a comprehension from left to proper (or from prime to backside, if it takes a number of strains) similar to you learn an…
[ad_2]