# in[8]
# 集合的遍历操作
# for循环
s={1, 2, 3, 'forever', 'love'}
for i in s:
print(i,end=" ")
# 带有元组的集合遍历
s={(1,2,3),("i","dss","777"),(0,8,9)}
for k,m,n in s:
print(k,"------",m,"------",n)
# out[8]
1 2 3 love forever
集合的内涵
#in[9]
s={1,2,3,4,5,6,7,8,9}
print(s)
# 普通的函数内涵
ss={i for i in s}
print(ss)
# 带条件的函数内涵
sss={i for i in s if i % 2==0}
print(sss)
# in[17]
# 成员检测
d={"one":1,"two":2,"three":3}
if 2 in d:
print("ture1")
if "two" in d:
print("ture2")
if ("two",2) in d:
print("ture3")
# out[17]
ture2
#in[18]
d={"one":1,"two":2,"three":3}
for k in d:
print(k,d[k])
for v in d.values():
print(v)
for k,v in d.items():
print(k,"----",v)
#out[18]
one 1
two 2
three 3
1
2
3
one ---- 1
two ---- 2
three ---- 3
字典的生成
# in【19】
d={"one":1,"two":2,"three":3}
# 常规的字典生成式
dd={k:v for k,v in d.items()}
print(dd)
# 加限制条件的字典生成式
ddd={k:v for k,v in d.items() if v % 2 == 0}
print(ddd)