How Remove Duplicate Letters In A String
Is there a way to remove duplicate characters? For example if we input 'hello', the output will be 'helo'; another example is 'overflow', the output would be 'overflw'; another exa
Solution 1:
Change string
to mystring
:
defremoveDupes(mystring):
newStr = ""for ch in mystring:
if ch notin newStr:
newStr = newStr + ch
return newStr
print removeDupes("hello")
print removeDupes("overflow")
print removeDupes("paragraphs")
>>>
helo
overflw
parghs
Solution 2:
yes with something called a set:
unique = set()
[ unique.add(c) for c in'stringstring' ]
Post a Comment for "How Remove Duplicate Letters In A String"