A random word from one of two lists

Bischoop Bischoop at vimart.net
Fri Jan 1 17:58:54 EST 2021


I have two lists *animal* and *fruit* and I try to get a random variable
animal or fruit and then random word from that list.
I thought that dictionary(*words*) could help me but no succes, the only way I've
done partially what was with list *kinds* and by using two times
random.choice. However print(kind) return me a list not a variable:
animal or fruit so now I'm kinda confuse if I can achieve that.



import random
animal = ['koala', 'kangaroo']
fruit = ['banana', 'apple']
kinds = [animal,fruit]
words = {'animals': animal, 'fruits': fruit}


kind = random.choice(kinds)
print(kind)
word = random.choice(kind)
print(word)
#output:
['kolala', 'kangaroo']
kangaroo

--
Thanks


More information about the Python-list mailing list