我问的问题基本上与 here 完全相同, 但对于 Python 3.4.0。
在 3.4.0 中,这段代码:
a = ["Spears", "Adele", "NDubz", "Nicole", "Cristina"]
b = [1, 2, 3, 4, 5]
combined = zip(a, b)
random.shuffle(combined)
a[:], b[:] = zip(*combined)
不起作用。在 3.4.0 中执行此操作的正确方法是什么?
最佳答案
在 python 3 中,zip
返回一个 zip
对象(即它是来自 python 2 的 itertools.izip
)。
你需要强制它实现列表:
combined = list(zip(a, b))
关于python-3.x - 在 Python 3.4 中随机化两个列表并维护顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23377560/