小编Geo*_*aou的帖子

Python:更新元组列表

我有一个像这样的元组列表:

list = [(1,'q'),(2,'w'),(3,'e'),(4,'r')]

我试图创建一个更新功能更新(项目,数字),搜索列表中的项目,然后更改数字.

例如,如果我使用更新(w,6),结果将是

list =   [(1, 'q'), (6, 'w'), (3, 'e'), (4, 'r')]
Run Code Online (Sandbox Code Playgroud)

我试过这段代码,但我有错误

if item in heap:
        heap.remove(item)
        Pushheap(item,num)
    else:
        Pushheap(item,num)
Run Code Online (Sandbox Code Playgroud)

Pushheap是一个将堆中的元组推到任何想法的函数吗?

python python-2.7 python-3.x

6
推荐指数
1
解决办法
757
查看次数

标签 统计

python ×1

python-2.7 ×1

python-3.x ×1