Python抽象数据结构(ADT)扩展

adt-extension的Python项目详细描述


adt分机

latest release

Python抽象数据结构(ADT)扩展。在

Install

pip install adt-extension

Import

^{pr2}$

扩展

目前该软件包具有ADT扩展:

ClassExtension ofDescription
^{}^{}Set with element type and validation rule.
^{}^{}Dictionary with the possibility of behavior of a ^{}.

设置

使用元素类型和将插入到集中的元素的验证规则设置。在

示例

fromadt_extensionimportSet# A set with only even integersset_int_even=Set(element_type=int,rule=lambdax:(x%2==0))# Elements that satisfies the element type and validation ruleset_int_even.update({4,6})# Elements that satisfies the element type, but not validation ruleset_int_even.update({5})# Elements that not satisfies the element typeset_int_even.update({"qwe",True})print(set_int_even)# Output:# Set({4, 6})# Remove element typeset_int_even.element_type=None# Remove validation ruleset_int_even.rule=None

SwitchDict

当试图访问Dictionary类中不存在的索引时,可以执行函数或返回值的字典。在

示例

fromadt_extensionimportSwitchDict# Same behavior of a normal dictionaryswitch_dict=SwitchDict({'Apartament':125,'House':250,'Condominium':300,})# Add default caseswitch_dict.default_case=999# List exampleproperties_list=['Apartament','House','Condominium','Treehouse','Hotel',]# Get valuesproperties_values=[switch_dict[x]forxinproperties_list]print(properties_values)# Output:# [ 125, 250, 300, 999, 999 ]# Remove default case, becomes a normal dictionaryswitch_dict.default_case=None

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

推荐PyPI第三方库


热门话题
java需要一种简单的方法来创建用于排序的comparator类   java getReadableDatabase和getWriteableDatabase无法解析   查找列表<Long>中与某个元素对应的所有索引的java方法   安卓将视图添加到ViewFlipper会导致java。StackOverflowerr语言   java根据它所包含的长“curTime”类字段将N的列表拆分为24(小时)   Android N中的Java8流API   自动生成Java策略文件的安全性   垃圾收集鼓励Java中的主要GC(但不是STW GC)   java如何检查UDP服务器上侦听的客户端数量   在前一台主机被Datastax Java驱动程序关闭后,Cassandra尝试重新连接到下一台主机   java如何使用Spring Boot创建部分代理   java是否有一个网站或资源可以完全比较EJB版本   java无需使用第三方库从gradle生成输出   继承由于这个多态性的基本示例中的语法有什么不同吗?(爪哇)   java字符串数组中的空字符串   java为什么CMS中的初始标记阶段是串行的   为什么Lucene有时与InChIKeys不匹配?   安卓通知Java应用程序数据库中的更改   java如何将单个json对象值解析为按钮   java打印堆栈将运行时错误跟踪到文件