标签:list bsp highlight 合并 range import 相关 zip div
通过 random.shuffle() 方法实现,直接对列表进行操作
>>> import random >>> a = list(range(4)) >>> a [0, 1, 2, 3] >>> random.shuffle(a) >>> a [3, 0, 1, 2]
通过 random.uniform() 方法实现
>>> random.uniform(0,10) 2.3591479768289227 >>> random.uniform(9,10) 9.402797721231435
通过 zip() 函数实现
>>> import random >>> a = list(range(4)) >>> a [2, 1, 0, 3] >>> b = a.copy() >>> random.shuffle(b) >>> b [2, 3, 0, 1] >>> list(zip(a,b)) [(2, 2), (1, 3), (0, 0), (3, 1)] >>> ba = list(zip(a,b)) >>> ba [(2, 2), (1, 3), (0, 0), (3, 1)] >>> c [2, 1, 0, 3] >>> list(zip(ba, c)) [((2, 2), 2), ((1, 3), 1), ((0, 0), 0), ((3, 1), 3)]
标签:list bsp highlight 合并 range import 相关 zip div
原文地址:https://www.cnblogs.com/alex-bn-lee/p/10326306.html