Advertisement
Dammiejoy20

Untitled

Mar 8th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. #Function to return sum of values for dictionary keys found in list
  2.  
  3. #This is the declared dictionary
  4. words = {"a": 5, "b": 3, "c": 10 }
  5. #This is the list accepted in the function
  6. elements = []
  7. #Function definition
  8. def sum_of_values(words, elements):
  9. #loop through the values to get the sum
  10.     sum_all = 0
  11.     for num in words.values():
  12.         if num in words.keys() in elements:
  13.             sum_all += num
  14.             print(sum_all)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement