"TB" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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 -- http://mail.python.org/mailman/listinfo/python-list