set*_*voy 0 python random loops
我有简单的循环:
vegetable_list = [('potatoes', 'potatoes', 'potatoes'), ('carrot', 'carrot'), ('onion', 'onion'), ('beet')]
akg = 0
print('Random vegetable: \n')
while akg < 5:
vegetable_random = [(i[0]) for i in vegetable_list]
print(random.choice(vegetable_random))
akg = akg + 1
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时 - 我得到了列表中项目的正常结果,这些项目有超过1个项目,但是'beet'- 我只得到符号,而不是完整的单词:
$ ./ovoch.py
Random vegetable:
potatoes
carrot
onion
b
b
Run Code Online (Sandbox Code Playgroud)
那么 - 我怎样才能从列表中得到单词?
| 归档时间: |
|
| 查看次数: |
46 次 |
| 最近记录: |