1、列表转集合(去重)
# 列表转集合(去重) list1 = [6, 7, 7, 8, 8, 9] set(list1) # {6, 7, 8, 9}
2、集合转列表
s={1,2L,3.1,1,"hello",1+4j} print s print type(s) li1=list(s) print li1 print type(li1)
输出
set([1, 2L, 3.1, (1+4j), 'hello']) [1, 2L, 3.1, (1+4j), 'hello']
上一篇:如何使用python中的slice函数生成切片
下一篇:python列表推导式指的是什么意思