default value in a list

Paul McGuire ptmcg at
Sat Jan 22 00:42:16 CET 2005

"TB" <tbolands at> wrote in message
news:1106349263.943972.72710 at
> Hi,
> Is there an elegant way to assign to a list from a list of unknown
> size?  For example, how could you do something like:
> >>>  a, b, c = (line.split(':'))
> if line could have less than three fields?
> Thanks,
> TB
I asked a very similar question a few weeks ago, and from the various
suggestions, I came up with this:

line = "AAAA:BBB"
expand = lambda lst,default,minlen : (lst + [default]*minlen)[0:minlen]
a,b,c = expand( line.split(":"), "", 3 )
print a
print b
print c

-- Paul

More information about the Python-list mailing list