hash of hashes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sfo

    #1

    hash of hashes

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


    thanks.

    --RR

  • Ant

    #2
    Re: hash of hashes


    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!

    Comment

    • Marc 'BlackJack' Rintsch

      #3
      Re: hash of hashes

      In <1152646733.156 556.190950@75g2 000cwc.googlegr oups.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

      Comment

      • Tim Chase

        #4
        Re: hash of hashes

        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




        Comment

        • sfo

          #5
          Re: hash of hashes

          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

          Comment

          Working...