Shuffle position of elements in a list
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Shuffling a list of objects in python
如果我有清单:
a = ["a","b","c", ...,"zzz"]
我如何随机移动其元素以获得列表:
b = ["c","zh", ...]
不消耗大量系统资源?
1 2 3 | import random b = list(a) random.shuffle(b) |
不知道有多少资源,但它在随机洗牌的异种类型,模块是这样做的。
1 2 3 | import random a = [1,2,3,4,5] random.shuffle(a) |