【发布时间】:2020-03-08 12:55:58
【问题描述】:
我正在尝试制作一个文本分类器应用程序。我有一个字符串数组,其中包含两个用逗号分隔的参数,如下所示:
pos_tweets = [('I love this car', 'positive'),
('This view is amazing', 'positive'),
('I feel great this morning', 'positive')]
我可以使用该字符串数组执行以下代码:
tweets = []
for (words, sentiment) in pos_tweets:
words_filtered = [e.lower() for e in words.split() if len(e) >= 3]
tweets.append((words_filtered, sentiment))
print(tweets)
带输出:
[(['love', 'this', 'car'], 'positive'), (['this', 'view', 'amazing'], 'positive'), (['feel', 'great', 'this', 'morning'], 'positive')]
我想要做的是将该字符串数组放入一个文本文件中,并且仍然能够以与上面相同的输出执行代码。
【问题讨论】:
-
请分享您迄今为止尝试写入文本文件的步骤,并指定您需要帮助的部分。如果您正在寻找“如何在 python 中将文本写入文件”这个问题的答案,我建议您看看其他类似这样的问题:stackoverflow.com/questions/31499257/…
标签: python arrays python-3.x text-classification naivebayes