如何在随机化一个列表的情况下并行遍历两个列表
How to iterate through two lists in parallel with one list randomized
This thread 解释了如何遍历两个并行列表。
但是,当我将该课程应用到打乱后的列表时,出现以下错误:"zip argument #2 does not support iteration."为什么打乱后的列表不支持迭代?我还能如何随机化答案选择的顺序?
import random
def answers():
answerList = random.shuffle([answer1, answer2, answer3, correct])
numberList = ["1: ", "2: ", "3: ", "4: "]
for x,y in zip(numberList,answerList):
print x,y
prompt = "What is the average migrating speed of a laden swallow?"
answer1 = "Gas or electric?"
answer2 = "Metric or English?"
answer3 = "Paper or plastic?"
correct = "African or European?"
print prompt
answers()
random.shuffle
随机 到位 。按如下操作:
answerList = [answer1, answer2, answer3, correct]
random.shuffle(answerList)
感谢 pacholik 提供解决方案。
import random
def answers():
answerList = [answer1, answer2, answer3, correct]
random.shuffle(answerList)
numberList = ["1: ", "2: ", "3: ", "4: "]
for x,y in zip(numberList,answerList):
print x,y
prompt = "What is the average migrating speed of a laden swallow?"
answer1 = "Gas or electric?"
answer2 = "Metric or English?"
answer3 = "Paper or plastic?"
correct = "African or European?"
print prompt
answers()
This thread 解释了如何遍历两个并行列表。
但是,当我将该课程应用到打乱后的列表时,出现以下错误:"zip argument #2 does not support iteration."为什么打乱后的列表不支持迭代?我还能如何随机化答案选择的顺序?
import random
def answers():
answerList = random.shuffle([answer1, answer2, answer3, correct])
numberList = ["1: ", "2: ", "3: ", "4: "]
for x,y in zip(numberList,answerList):
print x,y
prompt = "What is the average migrating speed of a laden swallow?"
answer1 = "Gas or electric?"
answer2 = "Metric or English?"
answer3 = "Paper or plastic?"
correct = "African or European?"
print prompt
answers()
random.shuffle
随机 到位 。按如下操作:
answerList = [answer1, answer2, answer3, correct]
random.shuffle(answerList)
感谢 pacholik 提供解决方案。
import random
def answers():
answerList = [answer1, answer2, answer3, correct]
random.shuffle(answerList)
numberList = ["1: ", "2: ", "3: ", "4: "]
for x,y in zip(numberList,answerList):
print x,y
prompt = "What is the average migrating speed of a laden swallow?"
answer1 = "Gas or electric?"
answer2 = "Metric or English?"
answer3 = "Paper or plastic?"
correct = "African or European?"
print prompt
answers()