list unpack trick?
aurora
aurora00 at gmail.com
Fri Jan 21 23:02:38 EST 2005
I find that I use some list unpacking construct very often:
name, value = s.split('=',1)
So that 'a=1' unpack as name='a' and value='1' and 'a=b=c' unpack as
name='a' and value='b=c'.
The only issue is when s does not contain the character '=', let's say it
is 'xyz', the result list has a len of 1 and the unpacking would fail. Is
there some really handy trick to pack the result list into len of 2 so
that it unpack as name='xyz' and value=''?
So more generally, is there an easy way to pad a list into length of n
with filler items appended at the end?
More information about the Python-list
mailing list