Re:Show HN: Array – A Better Python List
by brian_herman on Sunday January 10, 2021 @09:37AM
(#25714970)
Can you do the same thing with dicts and make it so d['non_existant_key'] does not create an exception?
[ Parent
| on HN ]
Re:Show HN: Array – A Better Python List
by basdftrewq on Sunday January 10, 2021 @09:40AM
(#25714992)
from collections import defaultdict
d = defaultdict(int)
d['non_existant_key']Not quite the same what OP asked for. This will create the key and assign value 0 to it.