List of all unique characters in a string?

后端 未结 7 1568
再見小時候
再見小時候 2020-11-27 18:03

I want to append characters to a string, but want to make sure all the letters in the final list are unique.

Example: \"aaabcabccd\"

7条回答
  •  我在风中等你
    2020-11-27 18:15

    char_seen = []
    for char in string:
        if char not in char_seen:
            char_seen.append(char)
    print(''.join(char_seen))
    

    This will preserve the order in which alphabets are coming,

    output will be

    abcd
    

提交回复
热议问题