multiple assignment
bruno at modulix
onurb at xiludom.gro
Tue Mar 28 06:29:27 EST 2006
Anand wrote:
>>>Wouldn't it be nice to say
>>>id, *tokens = line.split(',')
>>
>>
>>id, tokens_str = line.split(',', 1)
>
>
> But then you have to split tokens_str again.
>
> id, tokens_str = line.split(',', 1)
> tokens = tokens_str.split(',')
>
> this is too verbose.
>
head_tail = lambda seq: seq[0], seq[1:]
...
id, tokens = head_tail(line.split(','))
but I do like the syntax you're proposing !-)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list