1

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?

ishaishai
  • 73
  • 9

1 Answers1

1
mydict = {'key1':myfunc}
mydict['key1'](2) # or any other argument

So just define the function inside the dictionary

Shivam Singh
  • 1,584
  • 1
  • 10
  • 9