我有 3 个列表,我想将项目从一个列表移动到另一个列表。当我将一个项目移动到列表 3 时,一切正常。然后程序执行移动步骤两次。有人知道我怎样才能写得更好更短吗?
from os import system
list_a = [2]
list_b = [1]
list_c = [3, 4, 5, 6, 7, 8]
while True:
system("clear")
print "\nlist_a --->", list_a
print "list_b -----> ", list_b
print "list_c -----> ", list_c
item = input ("\n?> ")
place = [list_a, list_b, list_c]
place_name = ["List_A", "List_B", "List_C"]
for i, a in zip(place, place_name):
if item in i:
print "item", item, "--->", a
print "\n\n1) List_A"
print "2) List_B"
print "3) List_c"
这里似乎有问题。当一个项目移动到 list_3 脚本会执行两次
target_list = input("move to ---> ")
target_list = target_list - 1
target_list = place[target_list]
i.remove(item)
target_list.append(item)
print "\nitem moved!!"
# break out of loop that was missing before
break
raw_input()