python-3.x - 没有术语重复的随机字符串?
问题描述
我正在尝试在 Python 中随机化一些单词,但我得到带有重复术语的行。我怎样才能避免它?
我的代码:
words = ['blue,', 'orange,', 'yellow,', 'white,','pink,']
list=[]
for i in range(90):
r = ''.join(random.choices(words, k=random.randint(1, 5)))
if r not in list: list.append(r)
我得到什么:
orange,white,orange,white,blue, <-- Here Orange & white are twice
谢谢!
解决方案
推荐阅读
- reactjs - package.json 依赖项中的打字稿
- android - 如何在我的屏幕指针中添加动画?
- java - 如何剪切 LocalDateTime 格式字符串以将年份从 4 位限制为 2 位?
- java - 错误的文件关联.java文件作为objectiveC
- laravel - 订阅者中的事件未触发
- javascript - 如何根据键在 React JS 中创建动态表?
- javascript - 如何使用 redux 增加简单的计数器和带有对象组件的计数器
- python - 在程序中调用的新 tkinter 窗口中的 Excetue 按钮(Python 3.x)
- javascript - 简单的初学者承诺链
- backup - 使用 helm chart 时如何创建 keycloak 备份