Lists - Learn Python 3 - Snakify

Lesson 7. Lists




2/26. Lists

To store such data, in Python you can use the data structure called list (in most programming languages the term — “array” is used). A list is a sequence of elements numbered from 0, just as characters in the string. The list can be defined manually defining each of its elements, like here:

The list Primes has 6 elements, namely: Primes[0] == 2, Primes[1] == 3, Primes[2] == 5, Primes[3] == 7, Primes[4] == 11, Primes[5] == 13.

The list Rainbow has 7 elements, each of which is the string. Indexes of elements are written in square brackets.

Like characters in a string, list elements can also have negative index, for example, Primes[-1] == 13, Primes[-6] == 2. The negative index means we start at the last element and go left when reading a list.

Instructions


Since Primes[-1] is equal to 13 and Primes[-6] is equal to 2, it is quite easy to fill in the missing elements: Primes[-2] is equal to 11, Primes[-3] is equal to 7, Primes[-4] is equal to 5, Primes[-5] is equal to 3, Primes[-6] is equal to 2.
Primes = [2, 3, 5, 7, 11, 13]
Rainbow = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet']