The code: def split_string(source,splitlist): idx = 0 while idx < len(splitlist): if splitlist[idx] in source: source = ' '.join(source.split(splitlist[idx])) idx += 1 source = source.split(' ') print "source is", source, "and its type is", type(source) # <-- while "'' in source: # <-- source = source.remove('')
return source out = split_string('Hi! I am your Assistant Instructor, Peter.', '! ,.') print out The result: source is ['Hi', '', 'I', 'am', 'your', 'Assistant', 'Instructor', '', 'Peter', ''] and its type is <type 'list'> Traceback (most recent call last): File "/tmp/pytmp.py", line 18, in <module> out = split_string('Hi! I am your Assistant Instructor, Peter.', '! ,.') File "/tmp/pytmp.py", line 13, in split_string while '' in source: TypeError: argument of type 'NoneType' is not iterable Between the two arrows, 'source' inexplicably switches from <type list> to <type NoneType>. Why? Ray _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor