Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 具有列表的元组中的random.choice()返回不需要的项_Python_Loops_Random - Fatal编程技术网

Python 具有列表的元组中的random.choice()返回不需要的项

Python 具有列表的元组中的random.choice()返回不需要的项,python,loops,random,Python,Loops,Random,我有一个简单的循环: 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.choic

我有一个简单的循环:

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

那么-我怎样才能从列表中得到单词呢?

('beet')
不是一个元组,它与
'beet'
相同,因为元组是由
创建的,
,所以你想要
('beet',)
('beet')
不是元组,它与
'beet'
相同,因为元组是由
创建的,所以你想要
('beet',)

看,看,看,看,看,看,看,看,看,看,看,看,看,看,看,看,看,看
$ ./ovoch.py
Random vegetable:

potatoes
carrot
onion
b
b