额外的python集合-包(多集)和集合列表(有序集合)

collections-extended的Python项目详细描述


Build StatusCoverage

文档: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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在通配符泛型类型和泛型类型之间未经检查的强制转换   java Eclipse SWT Hello world教程:无法将显示解析为类型   java如何向远程用户发送注销消息?   java RDD之后的空文件是什么。保存ASTEXTFILE?   用户界面在java中创建一个htmljs UI GCalendar   Java多个哈希映射指向同一个键   Java Dowhile循环不工作?   oraclejava类。组织。阿帕奇。梁sdk。util。UserCodeException:java。sql。SQLException:无法创建PoolableConnectionFactory   java是org类型。日食用户界面。文本编辑器。*看不见   java有没有从弹出窗口复制eclipse中变量值的插件或快捷方式?   java getSubimage为我提供了期望值null   java我想让它变得更简单   swing AWTEventQueue0一直在运行,java中的程序变得非常慢   java Solr实例化类时出错:自定义类   java将ListView适配器移植到RecyclerView适配器   c#测试混合web和桌面应用程序的安全性