发布于 4年前

python在字符串中查找唯一元素

以下代码段可用于查找字符串中的所有唯一元素。我们使用set的特性,即集合中的所有元素都是唯一的

my_string = "aavvccccddddeee"
# converting the string to a set
temp_set = set(my_string)
# stitching set into a string using join
new_string = ''.join(temp_set)
print(new_string)
©2020 edoou.com   京ICP备16001874号-3