Python 利用内置set函数对字符串和列表进行去重的方法
如下所示:
# 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']) """
相关推荐
夜斗不是神 2020-11-17
huavhuahua 2020-11-20
Yasin 2020-11-16
xiaoseyihe 2020-11-16
千锋 2020-11-15
diyanpython 2020-11-12
chunjiekid 2020-11-10
wordmhg 2020-11-06
世事一场大梦 2020-11-17
xiaoseyihe 2020-11-16
Morelia 2020-11-03
CloudXli 2020-11-03
文山羊 2020-10-31
comtop0 2020-10-31
pythonxuexi 2020-10-30
三石 2020-10-29
chaochao 2020-10-27
PythonMaker 2020-10-27