例如此列表:
[['software', 'foundation'], ['of', 'the'], ['the', 'python'], ['software', 'foundation'],['of', 'the'], ['software', 'foundation']]
# 进行频率统计,例如输出结果为:
("['software','foundation']", 3), ("['of', 'the']", 2), ("['the', 'python']", 1)
例如此列表:
[['software', 'foundation'], ['of', 'the'], ['the', 'python'], ['software', 'foundation'],['of', 'the'], ['software', 'foundation']]
# 进行频率统计,例如输出结果为:
("['software','foundation']", 3), ("['of', 'the']", 2), ("['the', 'python']", 1)
from collections import Counter
data = [['software', 'foundation'], ['of', 'the'], ['the', 'python'], ['software', 'foundation'],['of', 'the'], ['software', 'foundation']]
cnt = Counter(map(tuple, data))
print(list(cnt.items()))
from itertools import groupby
data = ....
print [(k, len(list(g)))for k, g in groupby(sorted(data))]
2 回答5.3k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
4 回答1.5k 阅读✓ 已解决
3 回答1.4k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
2 回答965 阅读✓ 已解决
1 回答1.8k 阅读✓ 已解决