python 3键=lambda heappush

python 3键=lambda heappush,python,python-2.7,python-3.x,lambda,push,Python,Python 2.7,Python 3.x,Lambda,Push,这与python2配合得很好 第二个参数类型有时会从str变为dict,但这没关系 对于pyton3,我有这个 TypeError:' occurrences={'A': 5, 'R': 2, 'B': 2, 'C': 1, 'D': 1} tas = [(occ, lettre) for (lettre, occ) in occurrences.items()] heapify(tas) while len(tas) >= 2: print (tas) occ1, noe

这与python2配合得很好 第二个参数类型有时会从str变为dict,但这没关系

对于pyton3,我有这个 TypeError:'
occurrences={'A': 5, 'R': 2, 'B': 2, 'C': 1, 'D': 1}
tas = [(occ, lettre) for (lettre, occ) in occurrences.items()]
heapify(tas)
while len(tas) >= 2:
    print (tas)
    occ1, noeud1 = heappop(tas)
    occ2, noeud2 = heappop(tas)
#    print(type(noeud1))
#    print(type(noeud2))
    t=(occ1 + occ2, {0: noeud1, 1: noeud2})
#    print(occ1,noeud1)
#    print(occ2,noeud2)
#    print(t)
    heappush(tas, t)
#    heappush(tas, (occ1 + occ2, {0: noeud1, 1: noeud2}))
print (tas)