Created
November 15, 2014 18:02
-
-
Save AmaxJ/82cf68b8b2280e109a2f to your computer and use it in GitHub Desktop.
Character search script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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