[Tutor] I'm stumped.

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Jul 28 01:28:26 CEST 2005



On Wed, 27 Jul 2005, Nathan Pinno wrote:

> How do I split the list members up in the following code?

Hi Nathan,

Try using a string's split() method.  For example:

######
>>> "hello world this is a test".split()
['hello', 'world', 'this', 'is', 'a', 'test']
>>> "hello world this is a test".split('i')
['hello world th', 's ', 's a test']
######

By default, split() will break on whitespace, but we can give an optional
parameter to split on a different delimiting string.  For more details,
see:

    http://www.python.org/doc/lib/string-methods.html



More information about the Tutor mailing list