Вот пример предложения:
Код: Выделить всё
"My body lies over the ocean, my body lies over the sea."
Код: Выделить всё
"My body (2) lies over the ocean (3), my body (2) lies over the sea."
Однако я застрял в том, как собрать его обратно в нужный мне формат.
Вот фиктивная версия моей функции:
Код: Выделить всё
def word_score(text):
words_to_work_with = []
words_to_return = []
passed_text = TextBlob(passed_text)
for word in words_to_work_with:
word = word.singularize().lower()
word = str(word)
e_word_lemma = lemmatizer.lemmatize(word)
words_to_work_with.append(e_word_lemma)
for word in words to work with:
if word == 'body':
score = 2
if word == 'ocean':
score = 3
else:
score = None
words_to_return.append((word,score))
return words_to_return
- Как я могу собрать текст обратно и
- Должна ли эта логика быть помещена в функцию или вне ее?
Подробнее здесь: https://stackoverflow.com/questions/554 ... k-together
Мобильная версия