Read section 8.8 in the book and do the examples. There are lots of string methods you can use. Future projects will be easier if you're familiar with them. You can get a complete list of all the string methods in interactive mode:
>>> help(str)
This will bring up a long list of methods. Push the down arrow to scroll down (or the space bar to page down). The first bunch all start with two underscores. If you skip past them, you'll come to the other entries. The text that describes what each method does is the docstring for that method! (Bonus!) Feel free to play around with any of these. Press q to escape the help and return to interactive mode.
Read section 8.9 in the book and do the examples. Ahh, now we can simplify our conditional from last time's find_vowel:
def find_vowel(string): """Returns the index of the first vowel in string.""" for i in range(len(string)): char = string[i] if char in 'aeiou': #we've found the first vowel, return the index return i #after the loop, and no vowels. Return -1 for a failed search. return -1
Nice! And everything still works!
>>> find_vowel("banana cheese sandwich") 1 >>> find_vowel("Kyrgyzstan") 8 >>> find_vowel("fly") -1