[Python] Last element in OrderedDict

Discussão em 'Python' iniciado por Stack, Maio 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have od of type OrderedDict. I want to access its most recently added (key, value) pair. od.popitem(last = True) would do it, but would also remove the pair from od which I don't want.

    What's a good way to do that? Can /should I do this:

    class MyOrderedDict(OrderedDict):
    def last(self):
    return next(reversed(self))

    Continue reading...

Compartilhe esta Página