Something is wrong with my Code, I need my code to get last target string's position. (Homework 6 Unit 2, Udacity) def find_last(string_search, string_target): position = 0 while position != -1: position = string_search.find(string_target) string_search = string_search[ position:] end_pos = position return end_pos print find_last("kaaa","a")
Example: print find_last("aaaa","a") => 3
http://ideone.com/kwgyK i edited it and it's much better now but it won't work if the target string is at 0
that's easy to fix; just define end_pos to be -1 before the while loop begins so that if the target string simply doesn't exist, you won't get an error like: http://ideone.com/JiqgL To get it to work when it is at 0, you can assign position to the result of the find method and assign end_pos the value of position before the loop http://ideone.com/KoLT1
clever solution, thanks agd... i need to pratice more :-/
practice*
your solution is actually better than mine now... I'm going to 'rewrite' my hw :)
I still didn't start the robot car homework :( off I go.
oh, good luck with robot car homework and thanks again
trimmed my solution to 5 lines :-D
I'll think of a one-liner!
off I go to rewrite all my solutions to the udacity problems into one-liners.
Impressive agd, (y)
can you help me in this http://openstudy.com/study?login#/updates/4f55e90fe4b0862cfd071a91
Join our real-time social learning platform and learn together with your friends!