集合
##集合
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'}
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号