Skip to content

Instantly share code, notes, and snippets.

@AmaxJ
Created November 15, 2014 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmaxJ/82cf68b8b2280e109a2f to your computer and use it in GitHub Desktop.
Save AmaxJ/82cf68b8b2280e109a2f to your computer and use it in GitHub Desktop.
Character search script
# a script that searches a 1st string for all the characters present in the 2nd string, and returns the 2nd string
# if each character is present in the 1st. Returns 'give me soemthing that's not useless next time.' if not all
#characters are found
def fix_machine(search, target):
n = len(target) - 1
while n > -1:
search.find(target[n])
n = n - 1
if search.find(target[n]) == -1:
return "Give me something that's not useless next time."
return target
### TEST CASES ###
print "Test case 1: ", fix_machine('UdaciousUdacitee', 'Udacity') == "Give me something that's not useless next time."
print "Test case 2: ", fix_machine('buy me dat Unicorn', 'Udacity') == 'Udacity'
print "Test case 3: ", fix_machine('AEIOU and sometimes y... c', 'Udacity') == 'Udacity'
print "Test case 4: ", fix_machine('wsx0-=mttrhix', 't-shirt') == 't-shirt'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment