Exercise 61
Write a Python program as function which takes as parameter a string s and return an other string obtained by removing the duplicate characters of s. Example if s = "Programming", the function must retun "Progamin"
Solution
def removeDuplicate(s):
# initializing the string without duplicate characters
string_no_duplicate = ""
for x in s:
if x not in string_no_duplicate:
string_no_duplicate = string_no_duplicate + x
return string_no_duplicate
#Testing algorithm:
s = "Programming"
print("String without duplicate characters : '" , removeDuplicate(s) +"'")
# The output is : String without duplicate characters : ' Progamin'
Younes Derfoufi
my-courses.net
my-courses.net