首页 > 编程语言 > 详细

[python]List 过滤

时间:2020-02-15 09:43:56      阅读:71      评论:0      收藏:0      [点我收藏+]

获取数据库列表屏蔽系统自带数据库

# 原代码
db_list_result = [(master, ), (tempdb, ), (model, ), (msdb, ), (student, ), (school, )]
db_list = []
for _database in db_list_result:
    if master in _database:
        continue
    if tempdb in _database:
        continue
    if model in _database:
        continue
    if msdb in _database:
        continue
    db_list.append(_database[0])
print(db_list)

# 修改后代码
result2 = [db_name[0] for db_name in db_list_result if not (db_name[0] in [master,tempdb,model,msdb])]
print(result2)
#----输出结果------
[student, school]

 

[python]List 过滤

原文:https://www.cnblogs.com/leoshi/p/12310640.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!