Advertisement
ganiyuisholaafeez

Search and Add

Feb 22nd, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. """ This function searches the returns the index of the first occurence of
  2. letter s in a list of strings and sums all the indexes and the returns the totals """
  3. def run_a_search(Names):
  4.     total = 0           # Base Total
  5.     for Name in Names:
  6.         if "s" in Name:     # Searching for s
  7.             total += Name.index("s")    # Summing up the indexes
  8.     return total
  9.  
  10. print(run_a_search([])) # 0
  11. print(run_a_search(["mustache"])) # 2
  12. print(run_a_search(["mustache", "greatest"])) # 8
  13. print(run_a_search(["mustache", "pessimist"])) # 4
  14. print(run_a_search(["mustache", "greatest", "almost"])) # 12
  15. print(run_a_search(["Scholars", "Networks", "Is", "Best"])) # 17
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement