Autovivification

Je peux enfin mettre un terme sur une astuce Python que j’utilise depuis déjà longtemps: l'Autovivification.

from collections import defaultdict

def tree():
    return defaultdict(tree)

IP = tree()
IP['212.110.251.3']['212.112.245.2'] = 451

Related Posts

Questions, comments? Please use my public inbox by sending a plain-text email to ~cedric/public-inbox@lists.sr.ht.