import random
def test1(n):
list1 = [i for i in range(1, n + 1)]
list2 = list()
for i in range(1, n + 1):
list2.append(list1.pop(random.randint(0, n - i)))
print(list2)
test1(3)
def test2(n):
list4 = list()
while len(list4) != n:
a = random.randint(1, n)
if a not in list4:
list4.append(a)
print(list4)
test2(3)
python面试题-写出⼀个函数,给定参数 3,⽣成含有 3个元素值为 1~3 的数 组,元素顺序 随机,但值不重复
最新推荐文章于 2020-02-21 19:45:57 发布