defaultdict of defaultdict can use like this:(from Python: defaultdict of defaultdict at stackoverflow)
defaultdict(lambda : defaultdict(int))
Now,I want to use a defaultdict of OrderedDict,if I use like this,it will get error(TypeError: 'type' object is not iterable)
# tickets: List[List[str]]
# eg: [['a','b'],['c','d']]
m = defaultdict(lambda :OrderedDict(int))
for x, y in sorted(tickets):
m[x][y] += 1
So I have to use setdefault.
m = defaultdict(lambda :OrderedDict())
for x, y in sorted(tickets):
m[x].setdefault(y, 0)
m[x][y] += 1
How can I write just like the defaultdict(lambda : defaultdict(int)) ? I want to make my code more concise.(it means not use setdefault) Thanks~