On Fri, Jul 10, 2020 at 7:20 AM Steven D'Aprano <st...@pearwood.info> wrote:
>
> On Thu, Jul 09, 2020 at 10:25:46PM +1000, Chris Angelico wrote:
>
> > Getting a random element from a dict (not an arbitrary one but a
> > random one) definitely does have a use-case. I've wanted it at times.
> > Usually if I'm doing this in Python, I just pay the price and build
> > the list, but as proof that it's a logical and useful operation,
> > here's Pike's general random function:
> >
> > http://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/random.html
> >
> > If given a number, it picks a random number. If given an array, it
> > picks a random element. And if given a mapping (dictionary), it
> > returns (key,value), without first converting to a flat list.
>
> That's an existance proof that somebody else implemented the function,
> not a use-case. Getting a random key/item pair directly from a dict is a
> mechanism, not an explanation of why you need a random key-item pair.
>

And immediately above that part, I said that I had made use of this,
and had used it in Python by listifying the dict first. Okay, so I
didn't actually dig up the code where I'd done this, but that's a use
case. I have *actually done this*. In both languages.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/XP65AW7VQ7WSSKTNBKT6NBMM5GOYCYF3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to