Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How would I write a Python function to satisfy this doctest?
I have a test on Friday morning and can't figure out how to write this code. Assistance would be greatly appreciated!!
We have been using for & while loops, string slices, find() methods, etc.
Here is the question:
def remove_duplicates(strng):
"""
Returns a string which is the same as the argument except only the first occurrence of each letter is present. Upper and lower case letters are treated as different. Only duplicate letters are removed, other characters such as spaces or numbers are not changed.
>>> remove_duplicates("apple")
'aple'
>>> remove_duplicates("Mississippi")
'Misp'
>>> remove_duplicates("The quick brown fox jumps over the lazy dog.")
'The quick brown fx jmps v t lazy dg'
>>> remove_duplicates('121 balloons 2 u')
'121 balons 2 u'
"""
1 Answer
- Anonymous1 decade agoFavorite Answer
probably a horrible way to do it, but are you familiar with arrays? I'd just put each character into an array one character at a time, each time doing a loop to see if that character is already in the array, if it is then skip it