|
16 | 16 | A \pythonilIdx{list} is a mutable sequence of objects which can be accessed via their index~\cite{PSF:P3D:TPLR:S}. |
17 | 17 | They work very similar to the strings we already discussed in \cref{sec:str}, but instead of (only) characters, they can contain any kind of objects and they can be modified. |
18 | 18 |
|
19 | | -In \cref{lst:lists:lists_1}, we provide some first examples for using lists. |
| 19 | +With program \programUrl{lists:lists_1} in \cref{lst:lists:lists_1}, we provide some first examples for using lists. |
20 | 20 | A list can be defined by simply writing its contents, separated by~\pythonilIdx{,} inside square brackets~\pythonil{[...]}\pythonIdx{[\idxdots]}. |
21 | 21 | \pythonil{["apple", "pear", "orange"]} creates a list with three elements, namely the strings \pythonil{"apple"}, \pythonil{"pear"}, and~\pythonil{"orange"}. |
22 | 22 | If we want to store a list in a variable, then we can use the \pgls{typeHint}~\pythonil{list[elementType]}\pythonIdx{list!type hint} where \pythonil{elementType} is to be replaced with the type of the list elements~\cite{PEP585}. |
|
58 | 58 | \pythonIdx{del}\pythonIdx{list!del}\pythonil{del food[1]} deletes the second element from the list~\pythonil{food}. |
59 | 59 | The second element is \pythonil{pear} and if we print \pythonil{food} again, it has indeed disappeared. |
60 | 60 |
|
61 | | -In \cref{lst:lists:lists_2}, we illustrate some more operations on lists. |
| 61 | +In program \programUrl{lists:lists_2} in \cref{lst:lists:lists_2}, we illustrate some more operations on lists. |
62 | 62 | We begin again by creating a list, this time of numbers: \pythonil{numbers: list[int] = [1, 7, 56, 2, 4]} creates (and type-hints) a list of five integers. |
63 | 63 | If we want to know whether an element is included in a list, we can use the \pythonilIdx{in}~operator\pythonIdx{list!in}. |
64 | 64 | \pythonil{7 in numbers} returns \pythonil{True} if \pythonil{7} is located somewhere inside the list~\pythonil{numbers} and \pythonil{False} otherwise. |
|
96 | 96 | By the way, in the same manner as \pythonilIdx{not in} is the opposite of the \pythonil{in}~operator, \pythonilIdx{not is} is the opposite of~\pythonilIdx{is}: |
97 | 97 | \pythonil{cpy is not numbers} yields \pythonil{True} because \pythonil{cpy} is not the same object as \pythonil{numbers}. |
98 | 98 |
|
99 | | -In \cref{lst:lists:lists_3}, we continue our journey through the magical land of \python\ \pythonils{list}. |
| 99 | +Program \programUrl{lists:lists_3} given in \cref{lst:lists:lists_3} continues our journey through the magical land of \python\ \pythonils{list}. |
100 | 100 | You can add two lists~\pythonil{a} and~\pythonil{b} using \pythonilIdx{+}\pythonIdx{list!+}, i.e., do \pythonil{c = a + b}. |
101 | 101 | The result is a new list which contains all elements of the first list~\pythonil{a} followed by all the elements from the second list~\pythonil{b}. |
102 | 102 | Therefore, the expression \pythonil{[1, 2, 3, 4] + [5, 6, 7]} results in \pythonil{[1, 2, 3, 4, 5, 6, 7]}. |
|
0 commit comments