dictionary question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • José Carlos

    dictionary question

    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


  • Jeff Epler

    #2
    Re: dictionary question

    On Wed, Feb 04, 2004 at 10:47:49PM +0100, Jos� Carlos wrote:[color=blue]
    > 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.[/color]

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

    You can also change the keys by item assignment:[color=blue][color=green][color=darkred]
    >>> conex['tipoconex'] = None
    >>> conex
    >>> conex[/color][/color][/color]
    {'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

    Comment

    • Karl Pflästerer

      #3
      Re: dictionary question

      On 4 Feb 2004, José Carlos <- josecarlos@siad v.com wrote:
      [color=blue]
      > i have a dictionary. inside this dictionary i have several list and inside
      > each list i have data.[/color]
      [color=blue]
      > How can i do for add data to these list.[/color]
      [color=blue]
      > conex = {'tipoconex': ['1', '0'], 'conexionS': ['cliente1', 'cliente2'],
      > 'clave': ['pepo', 'joan'], 'usuario': ['pepe', 'juan']}[/color]

      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:
      [color=blue][color=green][color=darkred]
      >>> conex = {'tipoconex': ['1', '0'], 'conexionS': ['cliente1', 'cliente2'],[/color][/color][/color]
      .... 'clave': ['pepo', 'joan'], 'usuario': ['pepe', 'juan']}[color=blue][color=green][color=darkred]
      >>> conex['clave'].append('juan')
      >>> conex[/color][/color][/color]
      {'clave': ['pepo', 'joan', 'juan'], 'conexionS': ['cliente1',
      'cliente2'], 'tipoconex': ['1', '0'], 'usuario': ['pepe', 'juan']}[color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]


      KP

      --
      'Twas brillig, and the slithy toves
      Did gyre and gimble in the wabe;
      All mimsy were the borogoves,
      And the mome raths outgrabe. "Lewis Carroll" "Jabberwock y"

      Comment

      Working...