具有非连续索引的无限列表

sparsedlist的Python项目详细描述


稀疏列表

sparsedlist是具有非连续索引的无限列表。基于 Skip list数据结构。 使用Python3。

sparsedlist是一个列表结构,其中一组索引可以 “gaps”,您可以将值放入任何索引。换句话说, 结构类似于dict,但具有列表接口和排序数字 索引。

由于skiplist结构被用作机器,因此 前向迭代O(1)复杂度好 指数化/插入/删除与O(log n)的复杂性。

示例:

>>>fromsparsedlistimportSparsedList>>>s=SparsedList()>>>s[180]='rock the microphone'>>>s[10:20]=range(10)>>>print(s)SparsedList{{10:0,11:1,12:2,13:3,14:4,15:5,16:6,17:7,18:8,19:9,180:'rock the microphone'}}>>>print(s[180])rockthemicrophone>>>print(s[-1])rockthemicrophone>>>print(s[-2])None>>>print(list(s[18:23]))[8,9,None,None,None]>>>print(s[100500])None

默认情况下,sparsedlist替换none上的项 未设置。若要禁用此功能,请将required参数传递给构造函数。 然后在获取未设置项时将引发indexer错误。例如:

>>>fromsparsedlistimportSparsedList>>>s=SparsedList(required=True)>>>s[10:20]=range(10)>>>print(s[100500])Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"/usr/local/lib/python3.6/dist-packages/sparsedlist.py",line73,in__getitem__raiseIndexError("Item with index '{}' does not exist".format(item))IndexError:Itemwithindex'100500'doesnotexist>>>print(list(s[18:25]))Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"/usr/local/lib/python3.6/dist-packages/sparsedlist.py",line73,in__getitem__raiseIndexError("Item with index '{}' does not exist".format(item))IndexError:Itemwithindex'20'doesnotexist

依赖关系

pyskiplist仅限。测试时间为python3.6

安装

pip3 install sparsedlist

作者

伊戈尔·德卡赫,gosha753951@gmail.com

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

推荐PyPI第三方库


热门话题
java Apache Flink外部Jar   创建和强制转换对象数组时发生java错误   Java,添加数组   具有相同包结构和类的java JAR   java Jenkins未能构建Maven项目   java为什么一个forloop比另一个更快,尽管它们做的“一样”?   servlets在将“/”站点迁移到Java EE包时处理contextpath引用   无法解析java MavReplugin:2.21或其某个依赖项   泛型如何编写比较器来泛化Java中的两种类型的对象?   java Android Emulator未在netbeans上加载   多线程Java使用线程对数组中的数字求和:在同步块中使用新变量作为锁:差异   java如何在JSP/servlet中设置<input>标记的值?