December 2018
Beginner to intermediate
796 pages
19h 54m
English
Let's see another example of how to iterate over two sequences of the same length, in order to work on their respective elements in pairs. Say we have a list of people and a list of numbers representing the age of the people in the first list. We want to print a pair person/age on one line for all of them. Let's start with an example and let's refine it gradually:
# multiple.sequences.pypeople = ['Conrad', 'Deepak', 'Heinrich', 'Tom']ages = [29, 30, 34, 36]for position in range(len(people)): person = people[position] age = ages[position] print(person, age)
By now, this code should be pretty straightforward for you to understand. We need to iterate over the list of positions (0, 1, 2, 3) because we want to ...
Read now
Unlock full access