answer_list = ['a', 'b', 'c', 'd']
student_answers = ['a', 'c', 'b', 'd']
incorrect = []
我想在列表1比較指數0到列表2指數0,如果他們是平等的,在移動每個列表比較索引1。比較2所列出並返回指數值第三列表
在這種情況下,list1!中的index1!= index2在列表2中,所以我想將index + 1和不正確的學生答案(在這種情況下是字母c)附加到空列表中。這是我試過的 - 不成功。
def main():
list1 = ['a', 'b', 'c', 'd']
list2 = ['a', 'c', 'b', 'd']
incorrect = []
for x in list1:
for y in list2:
if x != y:
incorrect.append(y)
print(incorrect)
main()
你可以給一些*輸入/輸出*的例子嗎? – Christian
使用[enumerate()](https://docs.python.org/2/library/functions.html#enumerate) – agconti
您的代碼沒有按照您所描述的算法。你想遍歷_indices_並在每個索引處比較list1和list2,但是你的代碼循環遍歷一個列表的_values_,並且將每個值與另一個列表的每個值進行比較。 –