Why the mixture of lowercase and UpperCamelCase?
namedtuple
deque
Counter
OrderedDict
defaultdict
Why collections
instead
The collections module follows the PEP 8 Style Guide:
Modules should have short, all-lowercase names.
This is why it's collections
Almost without exception, class names use the CapWords convention.
This is why it's Counter
and OrderedDict
, because they are both classes:
>>> collections.Counter
<class 'collections.Counter'>
>>> collections.OrderedDict
<class 'collections.OrderedDict'>
namedtuple
is a function, so it does not follow the style guide mentioned above. deque
and defaultdict
s are types, so they also do not:
>>> collections.deque
<type 'collections.deque'>
>>> collections.namedtuple
<function namedtuple at 0x10070f140>
>>> collections.defaultdict
<type 'collections.defaultdict'>
Note: With Python 3.5, defaultdict and deque are now classes too:
>>> import collections
>>> collections.Counter
<class 'collections.Counter'>
>>> collections.OrderedDict
<class 'collections.OrderedDict'>
>>> collections.defaultdict
<class 'collections.defaultdict'>
>>> collections.deque
<class 'collections.deque'>
I assume they kept defaultdict
and deque
lowercase for backwards compatibility. I would not imagine they'd make such a drastic name change for the sake of a style guide.