标签:data soft section nbsp pytho 结果 linu 并集 set
1.python_1=[‘yy‘,‘lyf‘,‘wyb‘,‘xz‘,‘lx‘]
linux_2=[‘gql‘,‘ch‘,‘wyb‘,‘dc‘,‘xz‘]
ps=set(python_1)
ls=set(linux_2)
print(ps.intersection(ls)) //输出结果为{‘xz‘, ‘wyb‘},求集合交集
print(ps&ls) //输出结果为{‘xz‘, ‘wyb‘}
2.python_1=[‘yy‘,‘lyf‘,‘wyb‘,‘xz‘,‘lx‘]
linux_2=[‘gql‘,‘ch‘,‘wyb‘,‘dc‘,‘xz‘]
ps=set(python_1)
ls=set(linux_2)
print(ps.union(ls)) //输出结果为{‘ch‘, ‘lyf‘, ‘lx‘, ‘wyb‘, ‘gql‘, ‘xz‘, ‘dc‘, ‘yy‘},求集合并集
print(ps|ls) //输出结果为{‘ch‘, ‘lyf‘, ‘lx‘, ‘wyb‘, ‘gql‘, ‘xz‘, ‘dc‘, ‘yy‘}
3.python_1=[‘yy‘,‘lyf‘,‘wyb‘,‘xz‘,‘lx‘]
linux_2=[‘gql‘,‘ch‘,‘wyb‘,‘dc‘,‘xz‘]
ps=set(python_1)
ls=set(linux_2)
print(‘差集:‘,ps-ls) //输出结果为差集: {‘yy‘, ‘lx‘, ‘lyf‘},求集合差集
print(‘差集:‘,ps.difference(ls)) //输出结果为差集: {‘lx‘, ‘lyf‘, ‘yy‘}
print(‘差集:‘,ls-ps) //输出结果为差集: {‘dc‘, ‘ch‘, ‘gql‘}
标签:data soft section nbsp pytho 结果 linu 并集 set
原文地址:https://www.cnblogs.com/cxydnxs/p/12229750.html