嗨,我真的很困惑,我很難做出'我們完成'的部分。只有當我運行的代碼,其結果只會是['Hooray', ' Finally']
我不能使這個功能完全正確
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."]
"""
#I can't make we're done .
result = []
string=''
for ch in original:
if ch in separators:
result.append(string)
string=''
if '' in result:
result.remove('')
else:
string+char
return result
它實際上只在我應用了你所做的事情時才返回[],但是你所做的更合理,但我不知道它爲什麼返回此 – user3283844
@ user3283844不,它不返回[]。檢查我的代碼,有一個字符串= string + ch。你只有字符串+ ch,如果你有這樣的話,它返回[] – faboolous
哦,不,對不起,它的工作!我非常感謝你的幫助 – user3283844