SHARE
TWEET

Untitled

a guest Feb 21st, 2020 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """# This super_sum function accepts a list of one or more strings and sums up the
  2.     index position of the first occurence of the letter "s"
  3. """
  4.  
  5. def super_sum(ssum):
  6.     total = 0
  7.     s_counts = []
  8.    
  9.     for anystring in ssum:  #iterates over every character in the list passed to it
  10.         if "s" in anystring:  #checks for the character "s" in the elements of the strings passed to it
  11.             index_positions = (anystring.index("s"))
  12.             """#creating a variable to store the index position
  13.                of the first occurence of the character "s"
  14.            """
  15.             #print(index_positions)  #To check if i was getting the right index positions of the found "s" character in the string
  16.                                    
  17.             s_counts.append(index_positions)  #To add all the index positions to a list, to be able to iterate them and add them.
  18.             #print (s_count) #To check if the expected list was created
  19.    
  20.     for counts in s_counts:  #to iterate the generated index positions of the character "s", so as to add up easily
  21.         total += counts #the process of adding up the list of the index positions of the character "s"
  22.     return total
  23.  
  24.            
  25. print(super_sum(["Jesus", "sweet", "anybody", "grass"]))
  26. print(super_sum(["asus", "rest", "pies"]))
  27. print(super_sum([]))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top