Split

Michael A. Miller mmiller3 at iupui.edu
Tue Apr 18 16:29:09 EDT 2000


>>>>> "Penpal" == Penpal International <ppi at searchy.net> writes:

    > I've already managed to split a string with this:

    > split = regsub.split(line,'\s+')
[...]

    > But how can I print only the 5th for example?

You can also use the string module to split:

>>> import string
>>> line = 'This is a test, short and sweet, of split.'
>>> string.split(line)
['This', 'is', 'a', 'test,', 'short', 'and', 'sweet,', 'of', 'split.']
>>> string.split(line)[4]
'short'
>>> string.split(line,'a test')
['This is ', ', short and sweet, of split.']



More information about the Python-list mailing list