<s> "<STR_LIT>" <EOL> import collections <EOL> class LRUCache ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , capacity ) : <EOL> self . capacity = capacity <EOL> self . cache = collections . OrderedDict ( ) <EOL> def __contains__ ( self , key ) : <EOL> return key in self . cache <EOL> def __getitem__ ( self , key ) : <EOL> value = self . cache . pop ( key ) <EOL> self . cache [ key ] = value <EOL> return value <EOL> def __setitem__ ( self , key , value ) : <EOL> try : <EOL> self . cache . pop ( key ) <EOL> except KeyError : <EOL> if len ( self . cache ) >= self . capacity : <EOL> self . cache . popitem ( last = False ) <EOL> self . cache [ key ] = value </s>
