how best to split into singleton and sequence
Randy Bush
randy at psg.com
Tue Oct 18 18:36:34 EDT 2005
>>> l = []
>>> s = 'a|b'
>>> t, l = s.split('|')
>>> t
'a'
>>> l
'b'
>>> s = 'a|b|c|d'
>>> t, l = s.split('|')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: too many values to unpack
>>>
so, i imagine what is happening is the lhs, t,l, is really
(t, (l)), i.e. only two items.
so how should i have done this readably and simply?
randy
More information about the Python-list
mailing list