Unpacking a single tuple _or_ a pair
R.Brodie at rl.ac.uk
Mon Mar 13 10:54:50 EST 2000
"Oleg Broytmann" <phd at phd.russ.ru> wrote in message
news:Pine.LNX.4.21.0003131526010.14992-100000 at fep132.fep.ru...
> On Mon, 13 Mar 2000, Peter Bittner wrote:
> > for i in range(len(datalist)):
> > try:
> > value, text = datalist[i] # separate pair's values
> > except:
> > text, = datalist[i] # assume single value on fail
> > value = ''
> Just check len(datalist[i])...
and seeing as you've offered your code for public abuse ;),
for i in range(len(datalist)): is somewhat unidiomatic.
for t in datalist:
if len(t) etc works as well, and is somewhat cleaner.
More information about the Python-list