Re: [Tutor] split or replace

2009-06-05 Thread Chris Fuller
On Friday 05 June 2009 06:18, Norman Khine wrote: > Hello, > What is the way to group each value so that I get a list, from a string > like: > > dir = '/expert/forum/expert/expert' > list = ['/expert', '/forum', '/expert', '/expert'] > > I've tried: > >>> dir = '/expert/forum' > >>> dir.split('/')

Re: [Tutor] split or replace

2009-06-05 Thread Kent Johnson
On Fri, Jun 5, 2009 at 7:18 AM, Norman Khine wrote: > Hello, > What is the way to group each value so that I get a list, from a string like: > > dir = '/expert/forum/expert/expert' > list = ['/expert', '/forum', '/expert', '/expert'] Here is one way using re.split(): In [28]: import re In [29]: [

Re: [Tutor] split or replace

2009-06-05 Thread W W
On Fri, Jun 5, 2009 at 6:18 AM, Norman Khine wrote: > Hello, > What is the way to group each value so that I get a list, from a string > like: > > dir = '/expert/forum/expert/expert' > list = ['/expert', '/forum', '/expert', '/expert'] > > I've tried: > >>> dir = '/expert/forum' > >>> dir.split('

[Tutor] split or replace

2009-06-05 Thread Norman Khine
Hello, What is the way to group each value so that I get a list, from a string like: dir = '/expert/forum/expert/expert' list = ['/expert', '/forum', '/expert', '/expert'] I've tried: >>> dir = '/expert/forum' >>> dir.split('/') ['', 'expert', 'forum'] >>> dir.replace("/expert","") '/forum' >>> d