April 2019
Intermediate to advanced
646 pages
16h 48m
English
As you probably know, writing a piece of code such as this can be tedious:
>>> evens = [] >>> for i in range(10): ... if i % 2 == 0: ... evens.append(i) ... >>> evens [0, 2, 4, 6, 8]
This may work for C, but it actually makes things slower for Python for the following reasons:
A list comprehension is a better pattern for these kind of situations. It allows us to define a list by using a single line of code:
>>> [i for i in range(10) if i % ...
Read now
Unlock full access