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

hash of hashes

P: n/a
sfo
how do i create a hash of hash similar to perl using dict in python
$x{$y}{z}=$z
thanks.

--RR

Jul 11 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ant

sfo wrote:
how do i create a hash of hash similar to perl using dict in python
$x{$y}{z}=$z
Haven't done any Perl in a long while (thankfully ;-) ) so I'm not
quite sure on your syntax there, but here's how to do it in Python:
>>x = {'y': {'z': 'My value'}}
x['y']['z']
'My value'

Much easier to understand than that crazy perl syntax!

Jul 11 '06 #2

P: n/a
In <11**********************@75g2000cwc.googlegroups. com>, sfo wrote:
how do i create a hash of hash similar to perl using dict in python
$x{$y}{z}=$z
Just put dictionaries as values into a dictionary.

Ciao,
Marc 'BlackJack' Rintsch
Jul 11 '06 #3

P: n/a
how do i create a hash of hash similar to perl using dict in python
$x{$y}{z}=$z
Pretty much the same as in perl, only minus half the crazy abuses
of the ASCII character-set.

Okay...well, not quite half the abuses in this case...
>>x = {}
y = 42
z = 'foonting turlingdromes'
x[y] = {}
x[y][z] = 'crinkly bindlewurdles'
Or, if you want to do it in a single pass:
>>x = {y:{z:'crinkly bindlewurdles'}}
x
{42: {'foonting turlingdromes': 'crinkly bindlewurdles'}}
-tkc


Jul 11 '06 #4

P: n/a
sfo
Thanks to all for the feedback. it worked.

--RR

Tim Chase wrote:
how do i create a hash of hash similar to perl using dict in python
$x{$y}{z}=$z

Pretty much the same as in perl, only minus half the crazy abuses
of the ASCII character-set.

Okay...well, not quite half the abuses in this case...
>>x = {}
>>y = 42
>>z = 'foonting turlingdromes'
>>x[y] = {}
>>x[y][z] = 'crinkly bindlewurdles'

Or, if you want to do it in a single pass:
>>x = {y:{z:'crinkly bindlewurdles'}}
>>x
{42: {'foonting turlingdromes': 'crinkly bindlewurdles'}}
-tkc
Jul 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.