How does collections.defaultdict work?

前端 未结 15 2206
离开以前
离开以前 2020-11-22 12:50

I\'ve read the examples in python docs, but still can\'t figure out what this method means. Can somebody help? Here are two examples from the python docs

>         


        
15条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 13:14

    The documentation and the explanation are pretty much self-explanatory:

    http://docs.python.org/library/collections.html#collections.defaultdict

    The type function(int/str etc.) passed as an argument is used to initialize a default value for any given key where the key is not present in the dict.

提交回复
热议问题