集合

##集合

type({})
<class 'dict'>
type({"one"})
<class 'set'>
type({"one":1})
<class 'dict'>
{"fish","python"}
{'fish', 'python'}
{s for s in "fish"}
{'f', 'h', 's', 'i'}
set("fish")
{'f', 'h', 's', 'i'}

'c' in s
False
'c'not in s
True
for each in s:
print(each)


f
h
s
i
set([1,1,2,3,5])
{1, 2, 3, 5}
s=[1,1,2,3,4]
len(s)==len(set(s))
False
t=s.copy()
t
[1, 1, 2, 3, 4]
s=set("fish")
s
{'f', 'h', 's', 'i'}
s.isdisjoint(set("python"))
False
s.isdisjoint(set("java"))
True
s.issubset("fish.com.cn")
True
s.issubset("fish")
True
s.union({1,2,3})
{1, 's', 2, 3, 'i', 'f', 'h'}
s.intersection("fish")
{'f', 'h', 's', 'i'}
s.difference("fish")
set()
s.intersection("php","python")
{'h'}
s.difference("php","python")
{'f', 's', 'i'}
s<=set("fish")
True
s>set("fish")
False

s|{1,2,3}|set("python")

{1, 2, 3, 'h', 't', 'y', 's', 'n', 'o', 'i', 'p', 'f'}
s^set("python")

{'s', 'i', 'f', 't', 'y', 'o', 'n', 'p'}
t=frozenset("fish")

t

frozenset({'f', 'h', 's', 'i'})
s=set("fish")

s

{'f', 'h', 's', 'i'}
s.update([1,2],"23")

s

{1, 2, '2', 'h', 's', 'i', 'f', '3'}

posted @   奋斗吧-少年  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示