Python字串中查詢唯一元素

1。程式碼

str1=“aaaa1112222bb99999ccccdddd”

set1=list(str1)

new_str=‘’。join(set1)

print(new_str)

2。執行

Python字串中查詢唯一元素

執行效果

3。set函式

Set(集合)是沒有重複的物件集合,所有的元素都是唯一的。

4。join函式

join() 方法用於將序列中的元素與指定的字元連線生成一個新的字串。比如。

Python字串中查詢唯一元素

join函式