Exercises
A few exercises were already suggested. Let's list a few of these. (Note that the solution are not provided for these exercises.):
Write a list comprehension syntax for a nested
for
loop. Compare the timings of a nestedfor
loop and the list comprehension. Here is an example:x = [ i*j for i in range(4) for j in range(4)]
Write a generator expression for the preceding list comprehension. You just need to change the outer square brackets
[]
to the round brackets()
.