Problem in adding data to hash of hash

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhivya m
    New Member
    • Mar 2011
    • 2

    Problem in adding data to hash of hash

    I need to create a hash of hash in python.
    >>> x = {}
    >>> y = 42
    >>> z = 'first'
    >>> x = {y:{z:'first value'}}
    >>> x
    {42: {'first': 'first value'}}

    This is working but if I try to add another value, it is not working.. x is having only the current value..

    >>> y = 45
    >>> z = 'second'
    >>> x = {y:{z:'Second value'}}
    >>> x
    {45: {'second': 'second value'}}

    Now x is having only this value.

    Can anyone please tell me how to add values..
    Thank you..
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    The second values overlays the first value ("z") as you can not have duplicate keys in a dictionary. This is poor style. Consider SQLite instead (getting started) as you can have duplicate entries and can select for a match on multiple fields.

    Comment

    Working...