dictionary question

J

José Carlos

i have a dictionary. inside this dictionary i have several list and inside
each list i have data.

How can i do for add data to these list.

this is my code:

conex = {'tipoconex': ['1', '0'], 'conexionS': ['cliente1', 'cliente2'],
'clave': ['pepo', 'joan'], 'usuario': ['pepe', 'juan']}

thank you
Regards
Jose
 
J

Jeff Epler

i have a dictionary. inside this dictionary i have several list and inside
each list i have data.

How can i do for add data to these list.

You can change the dictionary by using methods that mutate its values:
conex = {'tipoconex': ['1', '0'], 'conexionS': ['cliente1', 'cliente2'], .... 'clave': ['pepo', 'joan'], 'usuario': ['pepe', 'juan']}
conex['tipoconex'].append(3)
conex['tipoconex'] ['1', '0', 3]
conex['tipoconex'][0] = 'None'
['None', '0', 3]

You can also change the keys by item assignment:
conex['tipoconex'] = None
conex
conex
{'clave': ['pepo', 'joan'], 'conexionS': ['cliente1', 'cliente2'],
'tipoconex': None, 'usuario': ['pepe', 'juan']}

If this doesn't help, you should tell us more about what you want to do.

Jeff
 
K

Karl =?iso-8859-1?q?Pfl=E4sterer?=

i have a dictionary. inside this dictionary i have several list and inside
each list i have data.
How can i do for add data to these list.
conex = {'tipoconex': ['1', '0'], 'conexionS': ['cliente1', 'cliente2'],
'clave': ['pepo', 'joan'], 'usuario': ['pepe', 'juan']}

If you write conex[Key] the object returned is the corresponding value;
if the value is a list you can use all list methods with that object.

E.g:
conex = {'tipoconex': ['1', '0'], 'conexionS': ['cliente1', 'cliente2'], .... 'clave': ['pepo', 'joan'], 'usuario': ['pepe', 'juan']}
conex['clave'].append('juan')
conex
{'clave': ['pepo', 'joan', 'juan'], 'conexionS': ['cliente1',
'cliente2'], 'tipoconex': ['1', '0'], 'usuario': ['pepe', 'juan']}

KP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top