In python believe it or not you actually have the power to put lists within lists. How would one do that? You can use the following code
list = [1, 2, 3, 4, 5]
for i in range(8):
list_2 = [1, 2, 3, 4, 5]
list.append(list_2)
print(list)
The above code creates a list within a list, there’s an even easier way to quickly create a list at runtime. The first element is the value being stored in the list and the rest is the list you’re creating.
list = [0.0 for x in range(8)]
print(list)
You can even nest lists this way as well, the following code creates a nested list, with 24 rows and 31 columns and assigns them all the value of “EMPTY” then prints the value stored in list index 24,31
Hours_in_Month = [[“EMPTY” for i in range(31)] for x in range(24)]
print(Hours_in_Month)
print(Hours_in_Month[23][30])
You can even set values to specific indexes in your nested lists.
Hours_in_Month = [[“EMPTY” for i in range(31)] for x in range(24)]
print(Hours_in_Month)
print(Hours_in_Month[23][30])
Hours_in_Month[0][0] = “Occupied”
print(Hours_in_Month[0][0])