Re: A random word from one of two lists

2021-01-03 Thread Mats Wichmann
On 1/3/21 11:34 AM, Richard Damon wrote: It depends on what distribution of results you want. Since the example had two equal length list is doesn't matter, but if, say, there were many more animals then fruit, your method would produce an animal more often than a fruit, but the two level method

Re: A random word from one of two lists

2021-01-03 Thread Richard Damon
On 1/3/21 12:38 PM, Mats Wichmann wrote: > On 1/3/21 5:30 AM, Bischoop wrote: >> On 2021-01-02, Stefan Ram wrote: >>> Bischoop writes: On 2021-01-02, Stefan Ram wrote: > Otherweise, I'd go this way without a dictionary. > import random > animal = ['koala', 'kangaroo'] > frui

Re: A random word from one of two lists

2021-01-03 Thread Mats Wichmann
On 1/3/21 5:30 AM, Bischoop wrote: On 2021-01-02, Stefan Ram wrote: Bischoop writes: On 2021-01-02, Stefan Ram wrote: Otherweise, I'd go this way without a dictionary. import random animal = ['koala', 'kangaroo'] fruit = ['banana', 'apple'] kinds = [animal,fruit] kind = random.choice( kinds

Re: A random word from one of two lists

2021-01-03 Thread Bischoop
On 2021-01-02, Stefan Ram wrote: > Bischoop writes: >>On 2021-01-02, Stefan Ram wrote: >>>Otherweise, I'd go this way without a dictionary. >>>import random >>>animal = ['koala', 'kangaroo'] >>>fruit = ['banana', 'apple'] >>>kinds = [animal,fruit] >>>kind = random.choice( kinds ) >>>result = ran

Re: A random word from one of two lists

2021-01-02 Thread Bischoop
On 2021-01-02, Stefan Ram wrote: > > The following might /not/ be good programming style, > but addresses the idea to choose a "variable". > I kinda like the below one. > import random > animal = ['koala', 'kangaroo'] > fruit = ['banana', 'apple'] > kinds = ['animal','fruit'] > variable = rand

Re: A random word from one of two lists

2021-01-01 Thread Bischoop
On 2021-01-02, Python wrote: > > >>> from random import choice > >>> choice(words[choice(list(words.keys()))]) > 'apple' > >>> choice(words[choice(list(words.keys()))]) > 'kangaroo' > >>> choice(words[choice(list(words.keys()))]) > 'koala' > >>> choice(words[choice(list(words.keys()))]) > 'apple'

Re: A random word from one of two lists

2021-01-01 Thread Bischoop
On 2021-01-01, Cameron Simpson wrote: > > kinds = list(words.keys()) > Yes, solved it with that exeactly. -- thanks -- https://mail.python.org/mailman/listinfo/python-list

Re: A random word from one of two lists

2021-01-01 Thread Marco Sulla
Try this: >>> animal = ['koala', 'kangaroo'] >>> fruit = ['banana', 'apple'] >>> words = {'animals': animal, 'fruits': fruit} >>> kinds = tuple(words.keys()) >>> kind = random.choice(kinds) >>> kind 'animals' >>> word = random.choice(words[kind]) >>> word 'koala' -- https://mail.python.org/mailma

Re: A random word from one of two lists

2021-01-01 Thread Cameron Simpson
On 01Jan2021 22:58, Bischoop wrote: >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

Re: A random word from one of two lists

2021-01-01 Thread Richard Damon
On 1/1/21 5:58 PM, Bischoop wrote: > 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

A random word from one of two lists

2021-01-01 Thread Bischoop
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 pr