How to remove duplicate letters from string in Python

3 Answers

0 votes
_str = "python php java c c++"

tmp = ""

for char in _str:
    if char not in tmp:
        tmp = tmp + char

_str = tmp

print(_str)
  
  
  
  
  
'''
run:
  
python javc+
 
'''
 

 



answered Jul 17, 2022 by avibootz
0 votes
_str = "python php java c c++"

_str = "".join(set(_str))

print(_str)
  
  
  
  
  
'''
run:
  
oyjvt +cpnah
 
'''

 



answered Jul 17, 2022 by avibootz
0 votes
_str = "python php java c c++"

_str = "".join(dict.fromkeys(_str))

print(_str)
  
  
  
  
  
'''
run:
  
python javc+
 
'''

 



answered Jul 17, 2022 by avibootz
...