English subtitles

← Selecting Substrings Solution - Programming Languages

Get Embed Code
5 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. Let's go through a possible answer together.
  2. Here I've written out a candidate example.
  3. Let's image that "bell hooks" is p and "curer bell" is q.
  4. The first thing we're going to do is find the index into p of the first space.
  5. Pindex space 0, 1, 2, 3, 4. This'll be 4 in our running example.
  6. Qindex--the location of this space in q might be different--0, 1, 2, 3, 4, 5.
  7. In fact in our example it is.
  8. Now what I want to do is select out the first word in p.
  9. I want everything from the beginning all the way up to, but not including, the space.
  10. This selection goes to the left as far as it can but does not include pindex,
  11. so it will be "bell."
  12. I could also have put a 0 in here. That would have been exactly the same.
  13. For q I don't want to start at position 5.
  14. I actually want to start at position 6, starting with the b and going to the end of the word.
  15. This is q's second word, which in our running example is also bell,
  16. since bell equals bell, we'll just return True.
  17. Curer Bell was actually a pseudonym, a false name, adopted by Charlotte Bronte, an author.