+ 3
Which is the best version of this code?
i write two codes.Both do se work but approach is different.i want to know which is the best approach. generally this is switch case in python. 1st approach. def h(string,x,y): return { 'add':x+y, 'mul':x*y, 'div':x/y, }.get(string,None) 2nd approach def h(string,x,y): return { 'add':lambda :x+y, 'mul':lambda :x*y, 'div':lambda :x/y, }.get(string, lambda :None)() which is the best version please tell me.
4 Respuestas
+ 1
I'd use the first version as the second one is unnecessarily complex. Theoretically, return lambda : None does the same as return None, but there really isn't any advantage to defining a temporary function that doesn't do anything but return None 🤔
+ 3
Anna you are absolutely right. i also choose this.
0
first
- 1
1st