This method is used to delete a key from the beginning.
If the last is False then this method would delete a key from the beginning of the dictionary. This serves as FIFO(First In First Out) in the queue otherwise it method would delete the key from the end of the dictionary.
For Better Understanding have a look at the code.
Original Dictionary
OrderedDict([('G', None), ('e', None), ('k', None), ('s', None), ('F', None), ('o', None), ('r', None)])
After Deleting Last item :
OrderedDict([('G', None), ('e', None), ('k', None), ('s', None), ('F', None), ('o', None)])
After Deleting Key from Beginning :
OrderedDict([('e', None), ('k', None), ('s', None), ('F', None), ('o', None)])
This method is used to move an existing key of the dictionary either to the end or to the beginning. There are two versions of this function -
If the last is True then this method would move an existing key of the dictionary in the end otherwise it would move an existing key of the dictionary in the beginning. If the key is moved at the beginning then it serves as FIFO ( First In First Out ) in a queue.
Original Dictionary
OrderedDict([('G', None), ('e', None), ('k', None), ('s', None), ('F', None), ('o', None), ('r', None)])
After moving key 'G' to end of dictionary :
OrderedDict([('e', None), ('k', None), ('s', None), ('F', None), ('o', None), ('r', None), ('G', None)])
After moving Key in the Beginning :
OrderedDict([('k', None), ('e', None), ('s', None), ('F', None), ('o', None), ('r', None), ('G', None)])
Basically, this method looks up a link in a linked list in a dictionary self.__map and updates the previous and next pointers for the link and its neighbors. It deletes that element from its position and adds it to the end or beginning depending upon parameter value. Since all of the operations below take constant time, the complexity of OrderedDict.move_to_end() is constant as well.