Is there a more succint way to write this?
f(a=a, b=b, c=c, d=d, e=e)
Background: I have a function with too many arguments
f(a, b, c, d, e):
pass
I my program I have local variables that are named exactly same as the function parameters.
a, b, c, d, e = range(5)
I would like to call the function with keyword arguments. Since the variables are named the same, this is how the call would look.
g = f(a=a, b=b, c=c, d=d, e=e) # this can get very long
Of course, I can pass the aruguments using position instead of keywords like this
g = f(a, b, c, d, e)
But a
, b
, c
, d
, e
are just the names of variables in this example and it is easy to see the correct order. However unfortunately the variables in my program are named more complicatedly and there is no easily discernible natural order. So I really like to pass them by keyword to avoid any mistakes.
lambda
has its own scope, so the local variables from its containing scope are not inlocals()
if it is used inside the lambda (but they will be inglobals()
). – Noyes