Use OrderedDict from collections module and join method to remove duplicate characters of a given string in Python.
Python program to remove duplicate characters of a given string Example
Simple example code.
from collections import OrderedDict
def rem_dup(str1):
# Lower case if needed
# str1 = str1.lower()
return "".join(OrderedDict.fromkeys(str1))
print(rem_dup("ABC ABC EFGH EFGH"))
print(rem_dup("ABC abc"))
Output:
![Python program to remove duplicate characters of a given string](https://i0.wp.com/tutorial.eyehunts.com/wp-content/uploads/2021/08/Python-program-to-remove-duplicate-characters-of-a-given-string.jpg?resize=228%2C152&ssl=1)
Do comment if you have any doubts and suggestions on this Python char string program.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.