我正在尝试编写一个算法:
我有如下OrderedDict
数据类型的输入:
odict_items([(3, [(0, 1), (1, 1), (1, 1)]), (11, [(0, 0), (1, 1), (1, 1)]), (12, [(0, 0), (1, 1), (1, 1)])])
我正在尝试编写一个函数来在每个中添加相同元组的数量,key
例如预期的输出,如下所示:如果有(1,1)
相同的元组1
,那么如果有两次2
,那么一个:
odict_items([(3, [(0, 1), (1, 1), (1, 1)],2), (11, [(0, 0), (1, 1), (1, 1)],2), (12, [(0, 0), (1, 0), (1, 1)]),1])
这是我的尝试,但如何改进它并将其添加到OrderedDict
?
def foo(OrderedDict):
listOfDic = list(makeDataStruc().items())
tupleCounter = 0
for i in range(len(listOfDic[1])):
if listOfDic[1][1][i][0] == 1 and listOfDic[1][1][i][1] == 1:
tupleCounter += 1
return tupleCounter
我在哪里犯错?