007python路--集合

集合set

去重

  a = [1,2,3,2,]   #传入集合的只能是字符串,列表,元组。

     a  = set(a)  #得到去重的集合

集合关系

  set('hello') == set('helloasd')    

  set('hello') != set('helloasd')  

  print( set('hello') set('hello world') )  #属于True

  set('hello') <= set('hello') 

  ---------------------------------------------------------------

  a = set([1,2,3,4,5,])  b = set([4,5,6,7,])

  交集   a & b

  并集   a  |  b

  差集   a  -  b

  对称差集  a^b  #{1, 2, 3, 6, 7}

 

 

  s = ['asd']

  a = set(s)

  

  a.update( [12 , 'eee'] )   #{'asd'  ,'eee', }  #元组/列表


    s.remove(内容)  

       s.clear()

       del s

 

 

 

posted @ 2018-10-11 17:40  zhaoweiscsuse  阅读(91)  评论(0)    收藏  举报