how to build hash tables?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • datulaida
    New Member
    • May 2007
    • 14

    #1

    how to build hash tables?

    Hi,
    first, i'm new with python.. so,i need a help..
    ok,i have a dictionary with many keys. this is a simple example.

    dict = { was : [ (2,1) ],
    a : [ (3,4) , (4,7) ],
    and : [ (1,7) ] }

    I want to hashing the dict value to the hash table. for example,

    hash "was" == was --> 2,1
    hash "a" == a --> 3,4 -->4,7

    How I do this with Python? Ideas?
    Thanks.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by datulaida
    Hi,
    first, i'm new with python.. so,i need a help..
    ok,i have a dictionary with many keys. this is a simple example.

    dict = { was : [ (2,1) ],
    a : [ (3,4) , (4,7) ],
    and : [ (1,7) ] }

    I want to hashing the dict value to the hash table. for example,

    hash "was" == was --> 2,1
    hash "a" == a --> 3,4 -->4,7

    How I do this with Python? Ideas?
    Thanks.
    Do not use a built-in function for a variable name (dict() is a built-in function). Dictionary keys must be immutable. Examples of immutable objects are strings and tuples.[code=Python]>>> dd = {'was' : [(2,1)], 'a' : [(3,4), (4,7)], 'and' : [(1,7) ]}
    >>> z = 'was'
    >>> dd[z]
    [(2, 1)]
    >>> dd['a']
    [(3, 4), (4, 7)]
    >>> dd['and'][0] = (0,7)
    >>> dd['and'][0]
    (0, 7)
    >>> [/code]You lost me when you said "I want to hashing the dict value to the hash table." Could you explain your problem better?

    Comment

    Working...