【发布时间】:2018-04-23 10:18:56
【问题描述】:
我有一本字典,它可以显示电影剧本中“女人”说了多少个单词。现在我想把字典的值加起来,这样我就得到了“女人”所说的单词的总数。 有没有办法做到这一点?
'WOMAN': Counter({'Mia': 4,
'a': 4,
'the': 4,
'and': 3,
'is': 3,
'on': 3,
'--': 3,
'it': 2,
'Then': 2,
'STUDIO': 2,
'Cappuccino,': 1,
'from': 1,
'her.': 1,
'No,': 1,
'I': 1,
'insist.': 1,
'She': 1,
'pays.': 1,
'smiles': 1,
'at': 1,
'drops': 1,
'bill': 1,
'in': 1,
'tip': 1,
'jar.': 1,
'watches': 1,
'as': 1,
'Woman': 1,
'walks': 1,
'off,': 1,
'joined': 1,
'screen:': 1,
'4:07.': 1})})
【问题讨论】:
-
sum(Counter({...}).values())
标签: python python-3.x dictionary counter