I need a help with a code here, i wanted to implement the switch case pattern in python so like some tutorial said , i can use a dictionary for that but here is my problem:<
You could hide the evaluation inside a lambda:
message = { 'create': lambda: msg(some_data),
'update': lambda: msg(other_data),
}
return message[type]()
As long as the names are all defined (so you don’t get a NameError), you could also structure it like this:
message = { 'create': (msg, some_data),
'update': (other_func, other_data),
}
func, arg = message[type]
return func(arg)