<jupyter_start><jupyter_text>hello<jupyter_code>class R:
    
    
    def __init__(self, size=3):
        self.__N=size
        self.__h={}
        self.__q=[]

        
        
    def __remove(self,k):
        if k in self.__h:
            del self.__h[k]
            self.__q.remove(k)
            
 
    def __make_recent(self,k):
        if k in self.__q: 
            self.__q.remove(k)
        self.__q.append(k)

        
    def __append(self,k,v):
        self.__h[k]=v
        self.__q.append(k)

        
    def __remove_oldest(self):
        if len(self.__q) >0:
            k = self.__q.pop(0)
            del self.__h[k]
        
        
    def put(self,k,v):
        self.__remove(k)
        
        if len(self.__h) >= self.__N :
            self.__remove_oldest()
            
        self.__append(k, v)
        
        
    def get(self, k):
        self.__make_recent(k)
        return self.__h[k]
    
    @property
    def q(self):
        return self.__q
        
        
        
r = R(3)
r.put('a','aa')
r.put('b','bb')
r.put('c','cc')
r.put('d','dd')
print(r.q)
r.get('c')
print(r.q)

assert r.q == ['b', 'd', 'c']

    
# %save 'wu2.py'<jupyter_output>['b', 'c', 'd']
['b', 'd', 'c']
{'fraction_non_alphanumeric': 0.16488925348646433, 'fraction_numerical': 0.004101722723543888, 'mean_word_length': 1.3874755381604698, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '576077', 'license': 'MIT', 'n_tokens_mistral': 475, 'n_tokens_neox': 464, 'n_words': 79, 'path': 'algorithms/WhatsUp2.ipynb', 'repo_name': 'vadim-ivlev/STUDY', 'size': '1219'}