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
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
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
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
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
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'
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
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
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
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
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
11 matches
Mail list logo