0

In Python 3.7 popitem () method return and remove random pair key-values. But in Python 3.10 popitem () return and remove LIFO pair key-values. What can i use instead popitem () in Python 3.10 for return and remove random pair in dictionary? Thanks!

  • Did you mean Python 3.5 rather than Python 3.7? In Python 3.7, dicts retain their insertion order, just like in Python 3.10. In Python 3.5, what `popitem` returns is based on the internal hash table, making it a bit unpredictable, but it's not really "random". – Mark Dickinson Feb 10 '22 at 18:29
  • @MarkDickinson Thanks! But question reamained) What dictionary method should i use instead **popitem**? For example, it is necessary in imitation for card games. – Dmitriy Domnikov Feb 10 '22 at 19:44
  • Would something like https://stackoverflow.com/questions/4859292/how-to-get-a-random-value-from-dictionary help? – Mark Dickinson Feb 10 '22 at 19:59
  • @MarkDickinson Yes! Thanks! but this way more code is needed) – Dmitriy Domnikov Feb 11 '22 at 09:10

0 Answers0