day17- geometry calculation intersection, difference, and sets .py

# #!/user/bin/env python
# # -*- coding:utf-8 -*-
# python = ['ww', 'xx', 'yy']
# linux = ['ww', 'xx', 'xz', 'zz', 'zd']
# python_and_linux = []
# for i in python:
# if i in linux:
# python_and_linux.append(i)
# print(python_and_linux)
#
# # 求交集
# p_n = set(python)
# l_n = set(linux)
# print(p_n.intersection(l_n))
# print(p_n & l_n)
#
# python = ['ww', 'xx', 'yy']
# linux = ['ww', 'xx', 'xz', 'zz', 'zd']
# p_n = set(python)
# l_n = set(linux)
# l_n.difference_update(p_n)
# print(l_n)
#
# python = ['ww', 'xx', 'yy']
Linux = # [ 'WW', 'XX', 'an xz', 'ZZ', 'ZD']
# P_n = SET (Python)
# L_n = SET (Linux)
# p_n.difference_update (L_n)
# Print (P_n)
#
# Python = [ 'WW', 'XX', 'YY']
# Linux = [ 'WW', 'XX', 'an xz', 'ZZ', 'ZD']
# P_n = SET (Python)
# L_n the sET = (Linux)
#
# # seek union,
# Print (p_n.union (L_n))
# Print (P_n | L_n)
#
# # differencing set
# Print (p_n.difference (L_n))
# Print (L_n - P_n)
# Print (P_n - L_n)
#
# # intersecting complement
# Print (P_n ^ L_n)
# Print (p_n.symmetric_difference (L_n))
# {# <<< 'an xz', 'ZZ', 'ZD', 'yy'}

# Isdisjoint intersection if otherwise returns false to true
S1 = {. 1, 2}
S2 = {. 1, 2,. 3}
print (s1.issubset (s2)) # s1 and s2 is a sub-set of
Print (s2.issubset (S1))

Print (s2.issuperset (S1))
Print (s1.issuperset (s2))

S1 = {. 1, 2}
. 1 = {S2, 2,. 3,. 4,. 5, 96}
s1.update ([. 1, 2,. 3,. 4, 982, 'Alex']) # updated plurality of values
Print (S1)

# s1.add (. 1 ) # update a value
s1.union (S2)
Print (S1)

S1 = {. 1, 2}
S2 = {. 1, 2,. 3,. 4,. 5, 96}
S = frozenset ( 'Hello') defines an immutable # set
Print (S)

# deduplication
names = [ 'Alex', 'Alex', 'PHP']
S = sET (names)
Print (S)
Print (names, '. 1')

# can not be removed repeating
Print (S)
S List = (names)
Print (S)

names = [ 'Alex', 'Alex', 'PHP']
s = list(set(names))
print(s)

Guess you like

Origin www.cnblogs.com/pythonzhao/p/11784972.html