Python 3.x 不知道如何使用python3.x,我尝试了s.split(';!';),但在本例中不起作用
我就是这样解决的Python 3.x 不知道如何使用python3.x,我尝试了s.split(';!';),但在本例中不起作用,python-3.x,Python 3.x,我就是这样解决的 def split_on_separators(original, separators): """ (str, str) -> list of str Return a list of non-empty, non-blank strings from the original string determined by splitting the string on any of the separators. separators i
def split_on_separators(original, separators):
""" (str, str) -> list of str
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.
>>> split_on_separators("Hooray! Finally, we're done.", "!,")
['Hooray', ' Finally', " we're done."]
"""
# To do: Complete this function's body to meet its specification.
# You are not required to keep the two lines below but you may find
# them helpful. (Hint)
result = [original]
return result
这里看起来一样。。。
def split_on_separators(original, separators):
""" (str, str) -> list of str
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.
>>> split_on_separators("Hooray! Finally, we're done.", "!,")
['Hooray', ' Finally', " we're done."]
"""
result = [original]
for sep in separators:
r = []
for sub in result:
r.extend(sub.split(sep))
result = r
return result