Advertisement
dprincef

Untitled

Mar 7th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def sum_of_values(my_dict,my_list): #Declares a sum_of_values function that accepts a dictionary and a list
  2.     g = [] #An empty list that stores the values of my_dict that appears in my_list
  3.     for i in my_list: #Implementation of the program that checks of a string in my_list is in my_dict and then returns the sum of the value/values
  4.         if i in my_dict.keys():
  5.             b = my_dict.get(i)
  6.             g.append(b)
  7.             r = sum(g)
  8.     print(r)
  9.            
  10.        
  11.            
  12. my_dict = {"a":2,"b":3,"c":4}
  13. sum_of_values(my_dict,["a","b"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement