具有特定功能的易用词典
dicts的Python项目详细描述
各种字典,你总是想,但从来没有做过。
检查完整文档site
安装
从pypi安装dicts:
easy_install dicts
或
pip install dicts
如果要从源代码安装它:
python setup.py install
用法
字典功能
加入:
>>> d1 = Dict({1 : 7, 2 : [1,2], 3 : 'a'}) >>> d1.join({1 : 2, 2 : [3], 3 : 'b'}) {1: 9, 2: [1, 2, 3], 3: 'ab'}
地图:
>>> d = Dict({'1' : 1, '2' : 2}) >>> d.map(lambda x: 1/3.0) >>> d {'1': 0.3333333333333333, '2': 0.3333333333333333}
来自重复:
>>> Dict.fromrepetitions([1,1,1,1,2]) {1: 4, 2: 1}
重新定位:
>>> d = Dict({'1': 1, '2' : 2, 'c' : 3}) >>> d.relookup('\d') [('1', 1), ('2', 2)]
特殊词典
- SortedDict系列
- nocasedict
- regexpdict