By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,768 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,768 IT Pros & Developers. It's quick & easy.

Problem in adding data to hash of hash

P: 2
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..
Apr 7 '11 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 624
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.
Apr 7 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.