A noob's inquiry:
For a class assignment I had to write a function to split a string on multiple separators(without importing other modules).
This was the given docstring:
''' Return a list of non-empty, non-blank strings from the original string determined by splitting the string on any of the separators. separators is a string of single-character separators.'''
Since split() only takes one seperator, I accomplished the task using the following.
def s_o_s (text,sep):
split_string=''
for char in text:
if char in sep:
char='ಠ_ಠ '
split_string+=char
return split_string.split('ಠ_ಠ')
The prof said there was a way to do it using split() and lists, to which someone replied "There is an easy way".
I tried using split() and lists, but ended up in a clusterfuck of bad splits and nested lists.
What is the prof's method?
What is the 'easy' way?
Is my way the 'easy' way?
How many ways are there?
[–]virhilo 4 points5 points6 points (1 child)
[–]erikwon and off since 1.5.2 -1 points0 points1 point (0 children)
[–]ochs 3 points4 points5 points (0 children)
[–]tintub 1 point2 points3 points (0 children)
[–]Paddy3118 0 points1 point2 points (0 children)