0

I have simple loop:

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

But when I run it - I got normal result for items in lists, which have more than 1 item, but for 'beet' - I got just symbol, instead of full word:

$ ./ovoch.py
Random vegetable:

potatoes
carrot
onion
b
b

So - how can I get just words from list?

setevoy
  • 4,374
  • 11
  • 50
  • 87

1 Answers1

5

('beet') is not a tuple, it's the same as 'beet' since tuples are created by the , - so you want ('beet',)

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636