Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def elim_duplicates(og_string, new_string=""):
- # Base case: return when the original gangster string is empty
- if len(og_string) == 0:
- return new_string
- # If the new_string is empty, seed it with the first char from the og_string
- if len(new_string) == 0:
- new_string += og_string[:1]
- # If the first letter in the og_string does NOT equal the last letter
- # we added to the new_string, add the letter to the new_string
- if og_string[0] != new_string[-1]:
- new_string += og_string[0]
- # Recursive case: chop off a letter from the og_string and call the func
- return elim_duplicates(og_string[1:], new_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement