如何使用变量替换列表中的项目?
def extension():
global presents
presents=[["Toy Car", 10.00, ""],["ES-335", 2500.00,""], ["Ben Teng Action Figure", 2.00, ""]]
for row in presents:
print(" ".join(map(str,row)))
choice = str(input("Choose an item from the list "))
count=0
while count ==len(presents)+1:
if choice==presents[count][0]:
然后,我想在他们在开放引号中选择的项目旁边的程序中插入他们之前提供的名称。我该怎么做?
答案 0 :(得分:0)
我能想到的最简单的方法是迭代列表并将值插入列表中的第3个位置。
见下文:
array = [["foo1", "bar1", ""],["foo2", "bar2", ""],["foo3", "bar3", ""]]
for i in array:
print(i)
for i in array:
i[2] = "var"
for i in array:
print(i)