Напишите функцию list_of_words, которая берет список строк, как указано выше, и возвращает список отдельных слов со всеми пробелами и пунктуацией (кроме апострофов/одинарных кавычек).using strip() в python
В моем коде удаляются периоды и пробелы, но не запятые или восклицательные знаки.
def list_of_words(list_str):
m = []
for i in list_str:
i.strip('.')
i.strip(',')
i.strip('!')
m = m+i.split()
return m
print(list_of_words(["Four score and seven years ago, our fathers brought forth on",
"this continent a new nation, conceived in liberty and dedicated",
"to the proposition that all men are created equal. Now we are",
" engaged in a great civil war, testing whether that nation, or any",
"nation so conceived and so dedicated, can long endure!"])
Мне нужно использовать метод strip() или split(), а не метод replace. –
Краткая версия: 'return [word.strip ('.,!') Для части в list_str для слова в part.split()]' – Matthias