How to create a list that has two mini lists inside it

Asked

Viewed 44 times

0

How to create only one list that has two mini lists within it. And the size is idetermined, that is, as long as user wants to add values within this list (internal) it will add.

  • 1

    What are "min list"?

  • Try to make it clearer by putting how you tried to do it, think it is, an example or at least an output you hope to receive.

1 answer

1

It is possible to do this in several ways, Python is great to work with lists:

>>> lista = []
>>> mini_lista1 = []
>>> mini_lista2 = []
>>>
>>> lista.append(mini_lista1)
>>> lista.append(mini_lista2)
>>>
>>> mini_lista_1.append('valor 1')
>>> mini_lista_1.append('valor 2')
>>> lista[0]
['valor 1', 'valor 2']
>>>
>>> lista[0].append("valor 3")
>>> lista[0]
['valor 1', 'valor 2', 'valor 3']
>>>
>>> lista[1].append("outra lista 1")
>>> lista[1].append("outra lista 2")
>>> lista[1].append("outra lista 3")
>>> lista[1]
['outra lista 1', 'outra lista 2', 'outra lista 3']
>>> lista
[['valor 1', 'valor 2', 'valor 3'], ['outra lista 1', 'outra lista 2', 'outra li
sta 3']]
>>>

more information here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.