如何刪除字符串中的其他內容並返回由其他字符串組成的列表?這是我寫的。提前致謝!!!刪除字符串中的項目
def get_poem_lines(poem):
r""" (str) -> list of str
Return the non-blank, non-empty lines of poem, with whitespace removed
from the beginning and end of each line.
>>> get_poem_lines('The first line leads off,\n\n\n'
... + 'With a gap before the next.\nThen the poem ends.\n')
['The first line leads off,', 'With a gap before the next.', 'Then the poem ends.']
"""
list=[]
for line in poem:
if line == '\n' and line == '+':
poem.remove(line)
s = poem.remove(line)
for a in s:
list.append(a)
return list
這非常含糊,除非您發佈了帶有代碼的示例輸入。編寫文本描述並不能解決問題的模糊性 – ha9u63ar 2015-04-01 22:51:46