列表list和集合set互转
代码
x = [1,1,2,2,3,2,3,4,5,6] y = [1,2,3,4,5] z = x + y print(z) # z = x - y # 会报错,不支持""-"操作 # print(z) sx = set(x) # 可以转集合,但会去除重复元素 sy = set(y) print(sx) print(sy) lsx = list(sx) # 可以转列表 lsy = list(sy) print(lsx) print(lsy)
x = [1,1,2,2,3,2,3,4,5,6] y = [1,2,3,4,5] z = x + y print(z) # z = x - y # 会报错,不支持""-"操作 # print(z) sx = set(x) # 可以转集合,但会去除重复元素 sy = set(y) print(sx) print(sy) lsx = list(sx) # 可以转列表 lsy = list(sy) print(lsx) print(lsy)