Python高级数据类型

除了python中默认提供的几种基本数据类型
collections模块还提供了几种特别好用的类型!

1.Conters  //计数器
2.Orderdict // 有序字典
3.defalutdict // 值带有默认类型的字典
4.namedtuple // 可命名元组,通过名字来访问元组元素
5.deque // 双向队列,队列头尾都可以放,也都可以取

这种数据结构people = [['男','xxx'],['男','yyy'],['女','qqq'],['女','ttt']] 转换成 {'男': ['xxx', 'yyy'], '女': ['qqq', 'ttt']} 这种数据类型 
for循环只需要写一句话哦

>>> people = [['男','xxx'],['男','yyy'],['女','qqq'],['女','ttt']]
>>> sort_info = collentions.defaultdict(list)

>>> for info in people:
...     sort_info[info[0]].append(info[1])
>>> print(sort_info)
defaultdict(<class 'list'>, {'男': ['xxx', 'yyy'], '女': ['qqq', 'ttt']})
原文地址:https://www.cnblogs.com/Treasuremy/p/10193051.html