[Python] Remove an element from dictionary python based on index

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    How can I remove an element from a dictionary based on the index? For example, if I have

    dict = {'s':0, 'e':1, 't':6}


    I want to remove and return 's' and 0, such that the dictionary has

    dict = {'e':1, 't':6}


    I have tried dictionary.popitem() that removes 't':6, dictionary.pop(key) removes a key from the dictionary, but I have no way of finding the key I want to remove, I only have the index.

    Continue reading...

Compartilhe esta Página