python 中的set与list,tuple

 1 __author__ = 'liunnis'
 2 #-*-coding:utf-8 -*-
 3 a=[1,2,3,4,4]
 4 print a
 5 print list(set(a))
 6 b=[str(i) for i in a]
 7 print list(set(b))
 8 #the result is
 9 # [1, 2, 3, 4, 4]
10 # [1, 2, 3, 4]
11 # ['1', '3', '2', '4']
12 c=[[1,2],[3,4],[5,5],[6,6],[7,8],[9,0],10,[11]]
13 print c
14 try:
15     print set(c)
16 except TypeError,e:
17     print'Error:',e
18 #the result is
19 # [[1, 2], [3, 4], [5, 5], [6, 6], [7, 8], [9, 0], 10, [11]]
20 # Error: unhashable type: 'list'

 

posted @ 2015-07-06 23:52  何似王  阅读(275)  评论(0编辑  收藏  举报