【发布时间】:2018-04-29 04:14:39
【问题描述】:
下面的字典给出了这个词和它的值:
keywords = {'alone': 1, 'amazed': 10, 'amazing': 10, 'bad': 1, 'best': 10, 'better': 7, 'excellent': 10, 'excited': 10, 'excite': 10}
字典后面是列表中的两条推文。 对于每条推文,我们需要找出其中有哪些来自 keywords 的词。
tweets = [['work', 'needs', 'to', 'fly', 'by', '', "i'm", 'so', 'excited', 'to', 'see', 'spy', 'kids', '4', 'with', 'then', 'love', 'of', 'my', 'life', '', 'arreic'], ['today', 'is', 'going', 'to', 'be', 'the', 'greatest', 'day', 'of', 'my', 'life', 'hired', 'to', 'take', 'pictures', 'at', 'my', 'best', "friend's", 'gparents', '50th', 'anniversary', '60', 'old', 'people', 'woo']]
目标是在每条推文行中找到关键字值的总和。
创建的代码需要是一个循环,因为有超过 2 条推文。 我不明白我应该如何执行这个过程。
欣赏您的洞察力!
【问题讨论】:
-
你试过什么?对您遇到的问题有任何疑问吗?
标签: python string list dictionary matching