Lists
Take a look at the snippet:
If you do something like this, you would lose the value previously stored in variable_2. Changing the order of the assignments will not help. You need a third variable that serves as an auxiliary storage.
This is how you can do it:
Python offers a more convenient way of doing the swap - take a look:
Creating Chess Board (MATRIX)
also known as two dimensional arrays
Python does not limit the depth of list-in-list inclusion. Here you can see an example of a three-dimensional array:
Imagine a hotel. It's a huge hotel consisting of three buildings, 15 floors each. There are 20 rooms on each floor. For this, you need an array which can collect and process information on the occupied/free rooms.
First step - the type of the array's elements. In this case, a Boolean value (True/False) would fit.
Step two - calm analysis of the situation. Summarize the available information: three buildings, 15 floors, 20 rooms.
Now you can create the array:
three dimensional arrays:
Now you can book a room for two newlyweds: in the second building, on the tenth floor, room 14:
and release the second room on the fifth floor located in the first building:
Check if there are any vacancies on the 15th floor of the third building:
Cube - a three-dimensional array (3x3x3)
Last updated