PYTHON之Ordered Dict
来源:互联网 发布:网络课程 知乎 编辑:程序博客网 时间:2024/05/22 06:29
python有一个排序字典对象,但是很少有人提及但是OrderedDict.__reversed__()方法不支持了,提供了对KEY的reverse操作。以下是对json的使用
>>> d = OrderedDict([('a', 'b'), ('c', 'd')])>>> d.update({'foo': 'bar'})>>> dcollections.OrderedDict([('a', 'b'), ('c', 'd'), ('foo', 'bar')])
以下的基本操作as keys(), values() and items() 还是支持的
>> d = OrderedDict([('a', 'b'), ('c', 'd')])>>> d.update({'foo': 'bar'})>>> dcollections.OrderedDict([('a', 'b'), ('c', 'd'), ('foo', 'bar')])
>>> d['spam'] = 'eggs'>>> d.keys()['a', 'c', 'foo', 'spam']>>> d.values()['b', 'd', 'bar', 'eggs']>>> d.items()[('a', 'b'), ('c', 'd'), ('foo', 'bar'), ('spam', 'eggs')]
>>> items = [('one', 1), ('two', 2), ('three',3), ('four',4), ('five',5)]>>> json.dumps(OrderedDict(items))'{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}'
更多细节,请点这里http://legacy.python.org/dev/peps/pep-0372/
0 0
- PYTHON之Ordered Dict
- python之dict
- python学习--之dict
- Python入门 之 dict
- Python之dict
- python基础之dict
- Python数据类型 之 dict
- Python之什么是dict
- Python之访问dict
- python数据类型之 dict(map)
- Python内置数据类型之Dict
- Python序列之字典(dict)
- Python基础数据结构之dict
- Python 之dict和set
- Python之dict的妙用
- Python基础之字典dict
- Python基础篇之dict
- python之dict学习笔记之二
- linux缓冲区溢出保护机制说明
- struts
- “年月日”录入时的一个小漏洞
- block的使用
- Hello World!
- PYTHON之Ordered Dict
- Android USB下的Accessory模式
- 玩转iPhone网络通讯之BSD Socket篇
- 【数据结构与算法】自己动手实现图的BFS和DFS(附完整源码)
- 从一个对象实例看数据抽象与封装
- IOS Layer的使用
- viewController详解
- TCP UDP 区别
- 数据分析入门方法