小编kev*_*lre的帖子

获取随机样本

我有这个清单:

colors = ["R", "G", "B", "Y"]
Run Code Online (Sandbox Code Playgroud)

我希望从中获得4个随机字母,但包括重复.

运行这个只会给我4个独特的字母,但绝不会有任何重复的字母:

print(random.sample(colors,4))
Run Code Online (Sandbox Code Playgroud)

如何获得4种颜色的列表,可能重复的字母?

python random python-3.x

27
推荐指数
3
解决办法
3万
查看次数

标签 统计

python ×1

python-3.x ×1

random ×1