【发布时间】:2018-02-25 13:56:06
【问题描述】:
我写了一个小单词生成器。我目前有生成器提供不同的单词,但不知道如何使用 split 功能在打印密码时在每个随机生成的单词之间插入连字符
当前输出:thisisapassword
期望的输出:this-is-a-password
answer = urllib.request.urlopen('http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain')
txt = answer.read()
words = txt.splitlines()
password = ''
for c in range(3):
password += random.choice(words)
print(password)
【问题讨论】:
-
你想要
join,而不是split- 将这三个词列成一个列表,然后用连字符将它们连接起来。
标签: python random generator hyphen