default value in a list

Steven Bethard steven.bethard at gmail.com
Sat Jan 22 01:30:08 CET 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. ;)

Steve



More information about the Python-list mailing list