码迷,mamicode.com
首页 > 编程语言 > 详细

[python]List 过滤

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

标签:结果   app   school   nbsp   result   temp   db_name   pre   span   

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

# 原代码
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 过滤

标签:结果   app   school   nbsp   result   temp   db_name   pre   span   

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

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!