Exercise

Finding strings in other strings

Many times when we are working with strings, we care about which characters are in the string. For example, we may want to know how many cookies in a list of cookies have the word Chocolate in them, or how many start with the letter C. We can perform these checks by using the in keyword and the .startswith() method on a string. We can also use conditionals on a list comprehension in the form of [action for item in list if something is true]. Using our cookies examples, it would be something like [cookie_name for cookie_name in cookies if 'chocolate' in cookie_name.lower()]. Note these checks are case sensitive so we're using the .lower() method on the string. We can also "chain" methods together by calling them one after the other.

Instructions

100 XP
  • Store and print a list of girl_names that start with s.
  • Store and print a list of girl_names with angel in them.