集合

1.创建

a = set('abcd')

2.添加

a.add('python') 将Python作为元素插入到set里面

a.update('python') 将python里面的每一个字母以及python本身作为元素插入到set里面

3.删除

a.remove('python')

4.成员关系

'c' in a 返回True

'c' not in a 返回False

5.交集 并集 差集 

a & b ; a | b; a - b.

6.List 元素去重

a = [1, 2, 3, 1, 2]

a = list(set(a))

a = forzenset('abc')  生成一个不可变集合

判断字符串a的所有字母是否都在b中出现

"""
判断字符串a中的字母是否全部出现在字符串b中
使用集合的update方法
将字符串b的所有字母转换成set 并且对b进行update(list(a)) 如果新的集合元素增加了则返回false
"""
a = "boy"
b = "boyabcd"
b_check = set(b)
b_check.update(list(a))
print (set(b) == set(b_check))
原文地址:https://www.cnblogs.com/wlc297984368/p/7581786.html