On Mon, Oct 11, 2021 at 12:17 AM Stephen J. Turnbull <stephenjturnb...@gmail.com> wrote: > > Steven D'Aprano writes: > > On Sun, Oct 10, 2021 at 01:51:52AM +0900, Stephen J. Turnbull wrote: > > > Christopher Barker writes: > > > > > > > But last time, one of the use cases was "get [an arbitrary] item > > > > from a dict", and there really is not a terribly easy (and > > > > efficient) way to do that now. > > > > > > What's wrong with thedict.popitem()? Works in Python 2.7, BTW. > > > > It removes the key and value, not just retrieve them. > > So does next() on an iterator. If you're sampling with replacement, > replace them. At least you can do that with dicts!
That's only relevant to the iterator itself. Using popitem mutates the underlying dict. That's a tad more likely to affect other parts of the code. 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/IWPPZY2IOJDIDNURPRCIYNQDJST2JWXZ/ Code of Conduct: http://python.org/psf/codeofconduct/