shuff打乱排序

shuff打乱排序,第1张

概述import randomalist=[1,2,3,4,5,6,7]random.shuffle(alist,random=None) def shuffle(self, x, random=None): if random is None: randbelow = self._randbelow for i in re
import randomaList=[1,2,3,4,5,6,7]random.shuffle(aList,random=None)

def shuffle(self,x,random=None):        if random is None:            randbelow = self._randbelow            for i in reversed(range(1,len(x))):                # pick an element in x[:i+1] with which to exchange x[i]                j = randbelow(i+1)                x[i],x[j] = x[j],x[i]        else:            _int = int            for i in reversed(range(1,len(x))):                # pick an element in x[:i+1] with which to exchange x[i]                j = _int(random() * (i+1))                x[i],x[j] = x[j],x[i]
shuffle源码

源码没有返回值,打乱的是原列表,所以不能print (random.shuffle(aList,random=None))

总结

以上是内存溢出为你收集整理的shuff打乱排序全部内容,希望文章能够帮你解决shuff打乱排序所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1025350.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存