额外的python集合-包(多集)和集合列表(有序集合)
collections-extended的Python项目详细描述
文档:http://collections-extended.lenzm.net/
github:https://github.com/mlenzen/collections-extended
PYPI:https://pypi.python.org/pypi/collections-extended
概述
collections_extended是一个python模块,它提供 一个bag类,也称为多集, 一个setlist类,它是一个唯一列表或有序集, 一个bijection类和RangeMap,它是从范围到值的映射。 也有冷冻(散列)袋和设置表的品种。
针对python 2.6、2.7、3.3、3.4、3.5、3.6、3.7、pypy&py3进行测试。
开始
>>>fromcollections_extendedimportbag,setlist,bijection,RangeMap>>>fromdatetimeimportdate>>>b=bag('abracadabra')>>>b.count('a')5>>>b.remove('a')>>>b.count('a')4>>>'a'inbTrue>>>b.count('d')1>>>b.remove('d')>>>b.count('d')0>>>'d'inbFalse>>>sl=setlist('abracadabra')>>>slsetlist(('a','b','r','c','d'))>>>sl[3]'c'>>>sl[-1]'d'>>>'r'insl# testing for inclusion is fastTrue>>>sl.index('d')# so is finding the index of an element4>>>sl.insert(1,'d')# inserting an element already in raises a ValueErrorTraceback(mostrecentcalllast):...raiseValueErrorValueError>>>sl.index('d')4>>>bij=bijection({'a':1,'b':2,'c':3})>>>bij.inverse[2]'b'>>>bij['a']=2>>>bij==bijection({'a':2,'c':3})True>>>bij.inverse[1]='a'>>>bij==bijection({'a':1,'c':3})True>>>us_presidents=RangeMap()>>>us_presidents[date(1993,1,20):date(2001,1,20)]='Bill Clinton'>>>us_presidents[date(2001,1,20):date(2009,1,20)]='George W. Bush'>>>us_presidents[date(2009,1,20):]='Barack Obama'>>>us_presidents[date(1995,5,10)]'Bill Clinton'>>>us_presidents[date(2001,1,20)]'George W. Bush'>>>us_presidents[date(2021,3,1)]'Barack Obama'>>>us_presidents[date(2017,1,20):]='Someone New'>>>us_presidents[date(2021,3,1)]'Someone New'
安装
pip install collections-extended
用法
^{tt7}$
课程
提供了六个新课程:
行李
- 行李
- 这是一个叫multiset的包。 冷冻袋
- 这是包的冻结(散列)版本。
设置列表
- 设置列表
- 一个有序的集合或唯一元素的列表,具体取决于您如何看待它。
- 冻结列表
- 这是setlist的冻结(哈希)版本。
映射
- 双射
- 一对一映射。 范围图
- 范围映射(数字/日期等)
Author: | Michael Lenzen |
---|---|
Copyright: | 2018 Michael Lenzen |
License: | Apache License, Version 2.0 |
Project Homepage: | |
https://github.com/mlenzen/collections-extended |