Is there any way to use the value of an argument to dynamically set the default of a keyword argument? I was thinking of something like this:
def foo(lst, r = 0, l = len(lst)): #I am referring to the "l = len(lst)" part
print r, l
foo([1,2,3])
This gives the following traceback:
Traceback (most recent call last):
File "C:/Python27/quicksort.py", line 25, in <module>
def foo(lst, r = 0, l = len(lst)):
NameError: name 'lst' is not defined
One could do something similar to this:
def foo(lst, r = 0, l = None):
if l is None:
l = len(lst)
print r, l
But I am hoping for a more elegant solution. Can anybody help?