Prerequisites for this course:
- Basic control statements, such as
- if-then-else conditional statement.
List comprehensions are a concise way to dynamically create and fill a list with values - no loop required! This way is visually very natural, and it's easy to grasp what's going on.
- create a list containing values from 1 to 10
mylist = [i for i in range(11)]
- create a list containing values from a second list, selecting only those that are greater than 0
mylist2 = [i for i in [-1, 0, 2, -5] if i > 0]