洗牌和重新洗牌列表中蟒蛇? [英] Shuffle and re shuffle list in python?

查看:136
本文介绍了洗牌和重新洗牌列表中蟒蛇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数字列表,我想用钥匙将它洗和重做。我使用它作为一个小的加密算法,所以我需要重新洗牌或者从suffled列表中的原始清单。

 原= [10,20,30,25,45,68,25]
洗牌=洗牌(原件,关键= 10)
打印洗牌
#>>> [25,30,25,10,20,45,68]
打印re_shuffle(洗牌,关键= 10)
#>>> [10,20,30,25,45,68,25]
 

这是我想要什么的想法。有一个库或算法呢?

解决方案

 随机进口洗牌

X = [[Ⅰ]为i的范围(10)]
洗牌(X)

打印x
 

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 ?

解决方案

from random import shuffle

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

print x

这篇关于洗牌和重新洗牌列表中蟒蛇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆