如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# coding:utf8
__author__ = 'libingxian'
__date = "20170415"
# 由于数据类型set本身具有无序,唯一值的特性,可以用内置函数set对字符串和列表进行去重,挺方便的
str = "asdfasdlklfgklgjsdfjkjl"
se = set ( str )
print se
li = [ 1 , "2" , 1 , "2" , "abc" , "123" ]
se = set (li)
print se
"""
输出结果:
set(['a', 'd', 'g', 'f', 'k', 'j', 'l', 's'])
set([1, '123', '2', 'abc'])
"""
|
以上这篇Python 利用内置set函数对字符串和列表进行去重的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/lbxoqy/article/details/70177327