mercredi 25 février 2015

Is there a name for a dictionary that returns the key as the value by default?


A dictionary that returns the key as the value by default can be used in cases where exceptions or translation is needed.


E.g. One could do



i18n = SpecialDict()

if spanish:
i18n["Hello"] = "Hola"

print(i18n["Test"]) # prints Test
print(i18n["Hello"]) # prints Hola if spanish


I18n is just an example, there are other (probably better) uses.


Is there a name for this dictionary / pattern?





Aucun commentaire:

Enregistrer un commentaire