On Sat, Oct 9, 2021, 10:44 PM Steven D'Aprano
Apart from a programming exercise and teaching moment, why would you want to get a random key and value from a dict? In 25-ish years of using Python, I think that the number of times I've needed to do that is zero. A random item from a list, dozens of times. But from a dict, never.
(I'm not even convinced that dict.popitem is useful either. But maybe that's just me, and others use it ten times a day.)
I've used dict.popitem() from time to time. Usually for the purpose of consuming items in a loop. But if I want to, I can put items back when I want to.
I don't see a need for anything past that. On rare occasion, this is fine:
somekey, someval = mydict.popitem()
mydict[somekey] = someval