View Single Post
Old 03-04-2021, 01:01 PM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,964
Karma: 29579516
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Actually its a lot easier than that.

Code:

def reverse_lookup(translated_string):
    if not hasattr(reverse_lookup, 'cache'):
         reverse_lookup.cache = {v: k for k, v _.__self__._catalog.items()}
    return reverse_lookup.cache.get(translated_string)
kovidgoyal is online now   Reply With Quote