ovunctuzel ovunctuzel - 9 months ago 59
Python Question

Parameter defaults using other parameters in python

Is it possible to do something like this in Python?

def func(list, l = len(list)):
print list, l

Answer Source

This is usually how it is done

def func(list, l = None):
    if l is None:
        l = len(list)
    print list, l

As a side note, avoid using built-in type/function names as your variable names(like list here)