list = ["60", "70", "40", "30", "73", "8"]
例如,我将如何进行
40
)int(40) - 30)
)'40'
)放回原来位置(第3个)的列表中?本案例中的更新列表应为:
["60", "70", "10", "30", "73", "8"]
答案 0 :(得分:2)
我认为你的意思是这个。
In [20]: l = ["60", "70", "40", "30", "73", "8"]
In [21]: l[2] = str(int(l[2])-30)
In [22]: l
Out[22]: ['60', '70', '10', '30', '73', '8']
答案 1 :(得分:2)
这是你想要做的吗?
In [2]: List=["60", "70", "40", "30", "73", "8"]
In [3]: List[List.index("40")] = str(int(List[List.index("40")]) - 30)
In [4]: List
Out[4]: ['60', '70', '10', '30', '73', '8']
答案 2 :(得分:2)
是否有理由将其从列表中删除?
y =["60", "70", "40", "30", "73", "8"]
x = int(y[2])
x -= 30
y[2] = str(x)
这感觉就像是简单的选项
答案 3 :(得分:1)
如果您想要替换多个项目,可以这样做:
myList = [str(int(i)-30) if i=="40" else i for i in myList]