I have a function with three parameters, parameters two and three have default values. The default value for parameter three is dependent on the properties of parameter one. However, I obviously cannot perform any operations on parameter one in the 'def' line so I'm having trouble finding an efficient way of defining the default value of parameter three. What is the standard way to do this in python?
The following code is what I'm working with. Line one throws an error because I haven't really defined 'data' yet. What is the best workaround?
def stooge_sort(data, a = 0, b = len(data) - 1):
if data[a] > data[b]:
data[a], data[b] = data[b], data[a]
if b + 1 - a >= 3:
thirds = (b + 1 - a) / 3
stooge_sort(data, a, b - thirds)
stooge_sort(data, a + thirds, b)
stooge_sort(data, a, b - thirds)
return data