unpack sequence to tuple?

John Nielsen nielsenjf at my-deja.com
Tue Jan 23 12:31:03 EST 2001


>
> Unfortunately, tuples and lists cannot be concatenated, which
> is why we need to cast the sequence into a definite form here --
> choosing list would of course work just as well:
>
> def padSequence(seq, length):
>     return (list(seq)+[None]*length)[:length]
>

Or you could just use extend. which may be a little clearer.

def padSequence(seq, length):
    a=list(seq)
    a.extend(list((None,)*length))
    return a[:length]

john


--
nielsenjf at my-Deja.com


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list