11.2.3.4 create nested lists Python. Nested lists (2D arrays)
Lists can be nested at any level. We will consider only two-dimensional (2D) lists. The 2D list is a data structure that can be represented in a square table. Each element of the list is also represented by a list (nested list). To refer to an element in a 2D list, you should at first determine the index of the list element (row) and then determine the index of the nested list element (column). For example, to get the value 8 from a table, you need to write the name of the list lst2D, then specify the index of the list element lst2D[1], then specify the index of the element in the nested list lst2D[1][2].
Question. Determine the result of a code snippet: print(lst2D[0][3], lst2D[2][2], lst2D[-1][-3])
How to create 2D lists filled with zeros?
How to fill a 2D list with dimensions n*m from the keyboard? If we want to input each value of an element in a new line:
If we want to input each row of elements in line:
If we want to input each row of integers on one line:
How to process each element of a matrix?
Iterating over elements. We can get value for each element
How to display all elements in a table?
or
Questions: 1. Explain what means 2D list/array. 2. Describe the main idea to process elements of the 2D list. Exercises: Ex. 1 Determine the result of code snippets Ex. 2 Fill the blanks Tasks:
| |
| |
Просмотров: 4336 | | |
Всего комментариев: 0 | |