default value in a list

Steven Bethard steven.bethard at
Fri Jan 21 19:30:08 EST 2005

Paul McGuire wrote:
> expand = lambda lst,default,minlen : (lst + [default]*minlen)[0:minlen]

Or if you're afraid of lambda like me:

def expand(lst,default,minlen):return (lst + [default]*minlen)[0:minlen]

or perhaps more readably:

def expand(lst, default, minlen):
     return (lst + [default]*minlen)[0:minlen]

No need for an anonymous function when you're naming it. ;)


More information about the Python-list mailing list