Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. def elim_duplicates(og_string, new_string=""):
  2.    
  3.     # Base case: return when the original gangster string is empty
  4.     if len(og_string) == 0:
  5.         return new_string
  6.    
  7.     # If the new_string is empty, seed it with the first char from the og_string
  8.     if len(new_string) == 0:
  9.         new_string += og_string[:1]
  10.    
  11.     # If the first letter in the og_string does NOT equal the last letter
  12.     # we added to the new_string, add the letter to the new_string
  13.     if og_string[0] != new_string[-1]:
  14.         new_string += og_string[0]
  15.    
  16.     # Recursive case: chop off a letter from the og_string and call the func
  17.     return elim_duplicates(og_string[1:], new_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement