问题如下:“通过组合上面 3 个列表中的 4 个单词来创建密码。打印密码”在该问题中,组合意味着将单词连接在一起。我的代码打印在下面,但我很好奇如何优化它。我确信我不需要将密码列出来。请随意包含我可以做的任何其他优化。谢谢!
import itertools
import random
nouns =[A large list of strings]
verbs = [A large list of strings]
adjs = [A large list of strings]
# Make a four word password by combining words from the list of nouns, verbs and adjs
options = list(itertools.chain(nouns, verbs, adjs))
password = []
for _ in range (4):
password.append(options[random.randint(0,len(options)-1)])
password = "".join(password)
print(password)
泛舟湖上清波郎朗
慕斯709654
四季花海
相关分类