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


thanks.

--RR

Search Discussions

  • Ant at Jul 11, 2006 at 7:53 pm

    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!
  • Marc 'BlackJack' Rintsch at Jul 11, 2006 at 7:56 pm

    In <1152646733.156556.190950 at 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
  • Tim Chase at Jul 11, 2006 at 8:05 pm

    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
  • Sfo at Jul 11, 2006 at 9:13 pm
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 11, '06 at 7:38p
activeJul 11, '06 at 9:13p
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase