dictionary question

Jeff Epler jepler at unpythonic.net
Wed Feb 4 16:59:49 EST 2004


On Wed, Feb 04, 2004 at 10:47:49PM +0100, Jos� Carlos wrote:
> 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




More information about the Python-list mailing list