我有两个清单:
Gigits_List
和Guesses_list
。你知道吗
我需要比较它们,找出哪里有牛和牛(就像真正的游戏一样)
例如:如果一个列表是['1', '3', '4', '6']
,而第二个列表是['2', '3', '6', '4']
。所以“2C 1B”是两头母牛和一头公牛
#setting the secret length
Secret_Length = int(raw_input("the secret length"))
#setting the secret base
Secret_Base = int(raw_input("secret base_between 6-10"))
#getting the secret from the user
Secret = str(raw_input("enter the secret"))
#checking if the secret in the right length
if (int(len(Secret)) != Secret_Length):
print "ERROR"
sys.exit()
Gigits_List = []
#checking if the number in the right base
for Each_Digigt in Secret:
Gigits_List.append(Each_Digigt)
if (int(Each_Digigt)>Secret_Base-1):
print "ERROR"
sys.exit
#getting a guess from the user
Guess = str(raw_input("enter the guess"))
Guesses_list = []
for Each_Guess in Guess:
Guesses_list.append(Each_Guess)
输出
使用list1[:i-removed]+list1[i-removed+1:]就可以了。但是list[:]每次都创建一个新的列表,这样会花费更多的时间。你知道吗
相关问题 更多 >
编程相关推荐