2024-04-23
Python Object Value Shorthand

Use sorcery

1
2
3
4
import sorcery
a,b,c = 1,2,3
mydict = sorcery.dict_of(a,b,c)

Related question

Read More

2023-12-27
Defaultdict And Counter

from collections import defaultdict, Counter
mydict = defaultdict(Counter) # remember to put callable or none as argument of defaultdict
mydict = defaultdict(lambda: defaultdict(lambda: 0)) # alternative
mydict['k1']['k2'] += 1 # two is ok, but not one or three
Read More