【发布时间】:2017-02-16 19:57:07
【问题描述】:
import random
global colours
global current
colours = ["Red","Yellow","Blue","Green","Orange","White"]
current = []
def randompicker():
for i in range(4):
current = random.choice(colours)
randompicker()
print(colours)
print(current)
嘿,所以上面的程序应该从名为 colors 的列表中随机添加 4 个元素到另一个名为 current 的列表中。我浏览了论坛,但找不到针对此案例的具体帮助。
简而言之,有没有一种快速有效的方法可以将一个列表中的 4 个随机元素直接添加到另一个列表中?
谢谢
【问题讨论】:
标签: python arrays list random append