class_counts = defaultdict (int)
First, about Defaultdict
In Python there is a module collections, which is interpreted as a data type container module. There is a collections.defaultdict () which is often used.
Example:
from Import = defaultdict (int) a[1] = 1a["b"]print " a[' a ']== ", a["a"]print A
----------
a[' a ']== 0
Defaultdict (<type ' int '), {' A ': 0, 1:1, ' B ': 0})
The result is easy to see, default (int) creates a similar dictionary object, where any of the values is an instance of int, and even if it is a nonexistent key, D[key] has a default value, which is the default value of int () 0.
Here Defaultdict (function_factory) constructs an object similar to dictionary, where the value of keys is determined by itself, but the type of values is the class instance of Function_factory, and has a default value.
Second, other types
--------------------------2016-7-30 08:15:12--
Source: Use and difference of "1" Python collections.defaultdict () and Dict
Python collections Defaultdict