Returning dictionary from a function

kk maymunbeyin at gmail.com
Thu May 14 17:38:55 EDT 2009


Hi

I am working on something here and I cannot get the full dictionary
out of a function. I am sure I am missing something here.

Anyways here is a simple code that repeats my problem. Basically I am
just trying to get that values function to return the diky as a
dictionary so that I can query values later.

thanks




def values(x):
    diky={}
    for a in range(x):
        a=a+100
        diky={chr(a):a}

        print diky
    return diky


b=values(5)
print type(b),len(b), b['f'] # gives error
print type(b),len(b), b['h'] # does not give error



More information about the Python-list mailing list