Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从defaultdict中提取重复值_Python_List_Dictionary - Fatal编程技术网

Python 从defaultdict中提取重复值

Python 从defaultdict中提取重复值,python,list,dictionary,Python,List,Dictionary,我有一个defaultdict定义如下: devicedict1=collections.defaultdict(列表) 设备dict包含一个索引键和两个值,如下所示: {0:['9085','9084'],1:['9084','5684'],2:['9084','3707'],3:['9084','3707'],4:['3707','9084','3707'],5:['9084','3707'],6:['3707','9084','5684'],8:['9084','3707'],9:['9

我有一个
defaultdict
定义如下:

devicedict1=collections.defaultdict(列表)
设备dict包含一个索引键和两个值,如下所示:

{0:['9085','9084'],1:['9084','5684'],2:['9084','3707'],3:['9084','3707'],4:['3707','9084','3707'],5:['9084','3707'],6:['3707','9084','5684'],8:['9084','3707'],9:['9084','3707'],10:['9084','3707'],11:['9084','5684','3784']
我想提取出现最多的元组(value,value),并打印它们

我已尝试使用计数器和项目()

e=计数器(devicedict1.items())
打印(e)
但它似乎不起作用。它应该给我们以下结果:

['9084', '3707']:30
['9084', '5684']:10
如果
map
将字典中的值映射到元组,则可以使用,因为与列表不同,元组是可散列的。要获取出现最多的
n
元组,有以下方法:


使用
计数器

Ex:

from collections import Counter

data = {0: ['9085', '9084'], 1: ['9084', '5684'], 2: ['9084', '3707'], 3: ['9084', '3707'], 4: ['3707', '9084'], 5: ['9084', '3707'], 6: ['3707', '9084'], 7: ['9084', '5684'], 8: ['9084', '3707'], 9: ['9084', '3707'], 10: ['9084', '3707'], 11: ['9084', '5684'], 12: ['3707', '9084']}
c = Counter(map(tuple, data.values()))
print(c.most_common(2))
[(('9084', '3707'), 6), (('9084', '5684'), 3)]
输出:

from collections import Counter

data = {0: ['9085', '9084'], 1: ['9084', '5684'], 2: ['9084', '3707'], 3: ['9084', '3707'], 4: ['3707', '9084'], 5: ['9084', '3707'], 6: ['3707', '9084'], 7: ['9084', '5684'], 8: ['9084', '3707'], 9: ['9084', '3707'], 10: ['9084', '3707'], 11: ['9084', '5684'], 12: ['3707', '9084']}
c = Counter(map(tuple, data.values()))
print(c.most_common(2))
[(('9084', '3707'), 6), (('9084', '5684'), 3)]

30
10
来自哪里?请显示整个样本输入30表示,30个重复记录和10个相同的记录。