Recurring patterns: Am I missing it, or can we get these added to the language?

Robin Stocker robin at nibor.org
Tue Apr 15 15:35:45 EDT 2008


Erich schrieb:
> This is like split() but returns a list of exactly lenght n. This is
> very useful when using unpacking, e.g.:
> x, y = nsplit('foo,bar,baz', ',', 2)

You could use the second argument of split:

   x, y = 'foo,bar,baz'.split(',', 1)

Note that the number has the meaning "only split n times" as opposed to 
"split into n parts".

Cheers,
   Robin



More information about the Python-list mailing list