python中集合的用法,归纳如下:
#!/bin/env python
#---(1)用集合的工厂方法set()和frozenset()---
#set方法
>>> s = set('cheeseshop')
>>> s
set(['c', 'e', 'h', 'o', 'p', 's'])
#frozenset方法
>>> t = frozenset('bookshop')
>>> t
frozenset(['b', 'h', 'k', 'o', 'p', 's'])
#type方法查看集合的类型
>>> type(s)
<type 'set'>
>>> type(t)
<type 'frozenset'>
#---(2)更新集合---
#使用集合的内建方法和操作符添加和删除集合的成员
#添加
&g......
阅读全文