Python: Best Way to remove duplicate character from string

后端 未结 7 936
借酒劲吻你
借酒劲吻你 2020-12-01 21:46

How can I remove duplicate characters from a string using Python? For example, let\'s say I have a string:

foo = \"SSYYNNOOPPSSIISS\"

How c

7条回答
  •  广开言路
    2020-12-01 22:07

    def removeDuplicate(s):  
        if (len(s)) < 2:
            return s
    
        result = []
        for i in s:
            if i not in result:
                result.append(i)
    
        return ''.join(result)  
    

提交回复
热议问题