nested dictionaries and functions in data structures.

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jan 7 06:06:28 EST 2014


Sean Murphy wrote:

> Only outstanding thing I have to work out is how to execute functions from
> a dictionary. I will continue searching on the net.

I don't quite understand this question. Do you mean something like this?


def spam(n):
    return "spam"*n

def eggs(n):
    return "eggs"*n

d = {1: spam, 2: eggs}

print( d[1](3) )
print( d[2](3) )



-- 
Steven




More information about the Python-list mailing list