[Tutor] split or replace

Norman Khine norman at khine.net
Fri Jun 5 13:18:18 CEST 2009


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'
>>> dir = '/expert/forum/expert'
>>> dir.replace("/expert","")
'/forum'

Thanks


More information about the Tutor mailing list