# 字符串去重
str1 = "壡壣壥夎夐夑夒囇巑囖灪瀸爥爨爥爨壣獿爩躞奱爨壣獿爩躞奱奊"
print(f"去重前字符数:{len(str1)} {str1}")
str2 = set(str1)
print(f"去重后字符数:{len(str2)} {''.join(str2)}\n")
# 列表去重,也是利用集合不能保存重复的元素。
lists = list(str1)
print(f"去重前字符数:{len(lists)} {''.join(lists)}")
l = list(set(lists)) # list去重
print(f"去重后字符数:{len(l)} {''.join(l)}\n")
for i in l:
print(i)
02-09
4666
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-08
4939
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-18
4778
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-13
2105
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交