Python how to create a dict of dict of list with defaultdict

后端 未结 3 1736
再見小時候
再見小時候 2021-01-18 13:20

How do I create a dict of dict of lists using defaultdict? I am getting the following error.

>>> from collections import defaultdict
>>> a=         


        
3条回答
  •  执念已碎
    2021-01-18 13:49

    It's a little tricky. You make a defaultdict of defaultdicts, like so:

    defaultdict(lambda: defaultdict(list))
    

提交回复
热议问题