<filename>udacity/cs101-intro-cs/code/lesson2/problem-set/find_last.py
# Define a procedure, find_last, that takes as input
# two strings, a search string and a target string,
# and returns the last position in the search string
# where the target string appears, or -1 if there
# are no occurrences.
#
# Example: find_last('aaaa', 'a') returns 3

# Make sure your procedure has a return statement.

def find_last(a,b):
	if (a.find(b) == -1):
		return -1
	
	location = a.find(b)
	while (a.find(b, location) != -1):
		location = a.find(b, location) + 1
	
	return location - 1

print find_last('aaaa', 'a')
#>>> 3

print find_last('aaaaa', 'aa')
#>>> 3

print find_last('aaaa', 'b')
#>>> -1

print find_last("111111111", "1")
#>>> 8

print find_last("222222222", "")
#>>> 9

print find_last("", "3")
#>>> -1

print find_last("", "")
#>>> 0
<filename>udacity/cs101-intro-cs/code/lesson2/problem-set/find_last.py
# Define a procedure, find_last, that takes as input
# two strings, a search string and a target string,
# and returns the last position in the search string
# where the target string appears, or -1 if there
# are no occurrences.
#
# Example: find_last('aaaa', 'a') returns 3

# Make sure your procedure has a return statement.

def find_last(a,b):
	if (a.find(b) == -1):
		return -1
	
	location = a.find(b)
	while (a.find(b, location) != -1):
		location = a.find(b, location) + 1
	
	return location - 1

print find_last('aaaa', 'a')
#>>> 3

print find_last('aaaaa', 'aa')
#>>> 3

print find_last('aaaa', 'b')
#>>> -1

print find_last("111111111", "1")
#>>> 8

print find_last("222222222", "")
#>>> 9

print find_last("", "3")
#>>> -1

print find_last("", "")
#>>> 0
# Define a procedure, find_last, that takes as input # two strings, a search string and a target string, # and returns the last position in the search string # where the target string appears, or -1 if there # are no occurrences. # # Example: find_last('aaaa', 'a') returns 3 # Make sure your procedure has a return statement. #>>> 3 #>>> 3 #>>> -1 #>>> 8 #>>> 9 #>>> -1 #>>> 0