Reputation: 73
I'm trying to use a dictionary by passing arguments to a function that is used by a key lets say for example:
def myfunc(myval):
print(myval)
mydict = {'key1':myfunc(a)}
mydict['key1'] = myfunc(2)
line 7, in mydict = {'key1':myfunc(a)} NameError: name 'a' is not defined
how its possible to be made?
Upvotes: 1
Views: 37
Reputation: 1624
mydict = {'key1':myfunc}
mydict['key1'](2) # or any other argument
So just define the function inside the dictionary
Upvotes: 1