Skip to content

Instantly share code, notes, and snippets.

@AO8
Last active September 27, 2017 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AO8/c6d6c3afe9901b00535f5935b9b386a2 to your computer and use it in GitHub Desktop.
Save AO8/c6d6c3afe9901b00535f5935b9b386a2 to your computer and use it in GitHub Desktop.
Simple practice exercise using Python's startswith() and index() methods.
words = ["hello", "Break", "cat", "blue", "brown", "zoo", "baby", "pie", "BOOM!"]
def b_count(lst):
# prints index and string of every element in a list that starts with the letter 'b' or 'B'
for i in lst:
if i.startswith("b") or i.startswith("B"):
print("Index " + str(lst.index(i)) + ": " + i)
b_count(words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment