Python collections.OrderedDict 参考
Python collections.OrderedDict 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
语法
from collections import OrderedDict
items = OrderedDict()
参数
iterable / mapping:用于初始化集合对象的数据。default_factory:defaultdict 创建缺省值时使用的工厂函数。
返回值
返回 Counter、defaultdict、deque 等容器对象或统计结果。
示例
from collections import OrderedDict
items = OrderedDict([("a", 1)])
print(items)
常见错误
- defaultdict 的默认工厂要传函数本身,不要传调用结果。
- Counter 统计的是可哈希元素,不可哈希对象不能直接作为键。
相关内容
相关内容
- Python collections.ChainMap 参考 Python collections.ChainMap 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.Counter 参考 Python collections.Counter 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.defaultdict 参考 Python collections.defaultdict 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.deque 参考 Python collections.deque 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.most_common 参考 Python collections.most_common 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.namedtuple 参考 Python collections.namedtuple 参考,整理标准库调用语法、参数、示例、返回值和常见错误。