Problem
Hello Peter, I understand that you would like to join several listas
into another one that would be type macro
, carrying the value of all others.
Possessing the following structure, regardless of the number of items included in them:
[[valores_lista_1], [valores_lista_2], [...]]
Lists can contain any mixes and combinations of data types, including other lists, thus allowing this crowding.
Solution:
A list can be created with harvests and can be created without content - to add later:
macro_list = []
And to do what you want, include other lists within another, you can use the append()
method, which adds a new element to the end of the list.
I have exemplified below:
# criando as listas para serem incluídas
first_list = [1, 2, 3]
second_list = [9, 1, 7]
third_list = [12, 91, 72]
# criando a lista que possuirá todas as outras
macro_list = []
# utilizando o metodo append()
macro_list.append(first_list)
macro_list.append(second_list)
macro_list.append(third_list)
When we check the value that is in the list using the function print()
print(macro_list)
We get the following result:
[[1, 2, 3], [9, 1, 7], [12, 91, 72]]
Note: The values referring to the inclusion of the lists:
macro_list[0] é referente aos valores da first_list
macro_list[1] da second_list e
macro_list[2] da third_list
If you want to add a new list in the macro, just use the same function append()
, including the next position with the desired values.