让我举个例子让你理解。虽然这个例子与你的例子有很大不同,但我发现它在解决这类问题时很有帮助。
from collections import Counter
a = [
(0, "Hadoop"), (0, "Big Data"), (0, "HBase"), (0, "Java"),
(1, "Postgres"), (2, "Python"), (2, "scikit-learn"), (2, "scipy"),
(2, "numpy"), (2, "statsmodels"), (2, "pandas"), (3, "R"), (3, "Python"),
(3, "statistics"), (3, "regression"), (3, "probability"),
(4, "machine learning"), (4, "regression"), (4, "decision trees"),
(4, "libsvm"), (5, "Python"), (5, "R"), (5, "Java"), (5, "C++"),
(5, "Haskell"), (5, "programming languages"), (6, "statistics"),
(6, "probability"), (6, "mathematics"), (6, "theory"),
(7, "machine learning"), (7, "scikit-learn"), (7, "Mahout"),
(7, "neural networks"), (8, "neural networks"), (8, "deep learning"),
(8, "Big Data"), (8, "artificial intelligence"), (9, "Hadoop"),
(9, "Java"), (9, "MapReduce"), (9, "Big Data")
]
#
# 1. Lowercase everything
# 2. Split it into words.
# 3. Count the results.
dictionary = Counter(word for i, j in a for word in j.lower().split())
print(dictionary)
# print out every words if the count > 1
[print(word, count) for word, count in dictionary.most_common() if count > 1]
现在这是您以上述方式解决的示例
from collections import Counter
a=[('example',123),('example-one',456),('example',987),('example2',987),('example3',987)]
dict = Counter(word for i,j in a for word in i.lower().split() )
print(dict)
[print(word ,count) for word,count in dict.most_common() if count > 1 ]