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第三方库


热门话题
如何使用Netbeans在Java中创建可执行文件   swing Set不透明(真/假);JAVA   java JPA无法删除具有onotomany关系和cascatype all的实体   java Hibernate自参考映射难题   Java/从字符串到Java代码   java为什么我已经在取整了,却得到了一个无终止小数扩展?   java Wicket onsubmit信息对话框   java如何使用类、类加载器和URL获取资源   java在多模块项目中使用License Maven插件时出错   java HashSet“contains”方法是如何工作的?   图像JavaPNG显示为黑色   java如何在保持内容完整的同时在两个活动之间切换?   JAVA在Tomcat 7.0.27中,WAR无法为Prod正确解包   listview的java onclicklistener   JavaXPages托管Bean可以跨多个数据库工作吗?   java无法停止服务空对象引用错误Android   java将UTF8编码的字符串转换为人类可读的字符串   JavaSpring与JBossSAML的集成   java如何替换AuthorizationCodeInstalledApp类?