I came across a question at Udacity Intro to Computer Science course:
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
I think there should be a much clean (shorter, fewer words) way of writing this function:
def find_last(s, t):
count = 0
if s.find(t) >= 0:
while s.find(t, count + 1) >= 0:
count += 1
return count
else:
return s.find(t)