#!/usr/bin/env python
#-*- coding: utf-8 -*-
'''
@创建时间:{2018/8/23}
@作者:sharefun2068
@邮箱:
@用途:
'''
list1=['192.168.1.100', '192.168.1.101', '192.168.1.102']
list2=['192.168.1.104', '192.168.1.100','192.168.1.105',]
list3=['192.168.1.100', '192.168.1.101']
#用列表解析的方法实现 ip地址是否包含在白名单中
#['4' if x == '1' else x for x in lst]
#d = [False if c not in list1 else True for c in list2 ]
d = [False for c in list2 if c not in list1]
dd = [False if c not in list1 else '11' for c in list2 ]
print(str(d)) #[False, False]
print(str(dd)) #[False, '11', False]
#获取2个列表差异元素
list4=[1,2,3,4,5]
list5=[3,4,5,6,7,8]
diff1=[c for c in list5 if c not in list4]
diff2=[c for c in list4 if c not in list5]
print diff1 #[6, 7, 8]
print diff2 #[1, 2]
diffTotal=diff1+diff2
print str(diffTotal)#[6, 7, 8, 1, 2]
#获取2个列表相同元素
list6=[1,2,3,4,5]
list7=[3,4,5,6,7,8]
list8=[c for c in list6 if c in list7]
print list8 #[3, 4, 5]