classLRUCache(object):def__init__(self,capacity):self.__capacity=capacityself.__dict={}# oldest to youngestself.__list=[]defget(self,key):ifnotself.__dict.has_key(key):return-1# move key to the tail of listifkey!=self.__list[-1]:self.__list.remove(key)self.__list.append(key)returnself.__dict[key]defset(self,key,value):ifself.__dict.has_key(key):self.__dict[key]=valueifkey!=self.__list[-1]:self.__list.remove(key)self.__list.append(key)else:iflen(self.__dict)==self.__capacity:self.__dict.pop(self.__list[0])self.__list.pop(0)self.__dict[key]=valueself.__list.append(key)