您的位置:首页 > 编程语言 > Python开发

python 中的set与list,tuple

2015-07-06 23:52 756 查看
__author__ = 'liunnis'
#-*-coding:utf-8 -*-
a=[1,2,3,4,4]
print a
print list(set(a))
b=[str(i) for i in a]
print list(set(b))
#the result is
# [1, 2, 3, 4, 4]
# [1, 2, 3, 4]
# ['1', '3', '2', '4']
c=[[1,2],[3,4],[5,5],[6,6],[7,8],[9,0],10,[11]]
print c
try:
print set(c)
except TypeError,e:
print'Error:',e
#the result is
# [[1, 2], [3, 4], [5, 5], [6, 6], [7, 8], [9, 0], 10, [11]]
# Error: unhashable type: 'list'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: