Ch 4 Python

4.5 Lists of lists

Finally, note that it is quite possible to build lists of lists. This feature can be handy sometimes. For example: >>> enclos1 = [ ‘giraffe’ , 4 ] >>> enclos2 = [ ‘tiger’ , 2 ] >>> enclos3 = [ ‘monkey’ , 5 ] >>> zoo = [ enclos1, enclos2, enclos3 ] >>> zoo [[‘giraffe’, 4], [‘tiger’, […]

Ch 4 Python

4.3 Negative cueing and slices

The list can also be indexed with negative numbers in the following format: list: [ ‘giraffe’ , ‘tiger’ , ‘monkey’ , ‘mouse’ ] positive index: 0         1        2         3 negative index: – 4       – 3       – 2        – 1 or: list: [ ‘A’ , ‘C’ , ‘D’ , ‘E’ , ‘F’ , ‘G’ , ‘H’ , ‘I’ , ‘K’ , ‘L’ ] positive index: 0   1   2   3   4   5   6   7   8   9 negative index: – 10  – 9  – 8  – 7  – 6  – 5  – 4  – 3 – 2  – 1 Negative indices return to count from the […]

Ch 4 Python

4.1 Definition

A list is a data structure that contains a series of values. Python allows the construction of list containing values ​​of different types (such as an integer and string), which gives them great flexibility. A list is declared by a set of values ​​(do not forget the quotes, single or double, in the case of […]