Hacker News new | ask | show | jobs
by basdftrewq 1986 days ago

    from collections import defaultdict

    d = defaultdict(int)

    d['non_existant_key']
1 comments

Not quite the same what OP asked for. This will create the key and assign value 0 to it.