Shuffle and re shuffle list in python? [duplicate]

╄→гoц情女王★ 提交于 2019-12-25 02:29:34

问题


I have a list of numbers and I want to shuffle it with a key and redo it. I am using it as a small encryption algorithm so I need to re-shuffle or get the original list from the suffled list.

original = [10, 20, 30, 25, 45, 68, 25]
shuffled = shuffle(original, key=10)
print shuffled
# >>> [25, 30, 25, 10, 20, 45, 68]
print re_shuffle(shuffled, key=10)
# >>> [10, 20, 30, 25, 45, 68, 25]

This is the idea of what I want. Is there a library or algorithms for this ?


回答1:


from random import shuffle

x = [[i] for i in range(10)]
shuffle(x)

print x


来源:https://stackoverflow.com/questions/21337456/shuffle-and-re-shuffle-list-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!