Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #infytq
  2. '''Write a python function to create and return a new dictionary from the given dictionary(item:price).
  3. Given the following input, create a new dictionary with elements having price more than 200.
  4.  
  5. prices = {'ACME': 45.23,'AAPL': 612.78, 'IBM': 205.55,'HPQ': 37.20,'FB': 10.75}
  6. Sample Input:
  7. { 'ACME': 45.23,'AAPL': 612.78, 'IBM': 205.55,'HPQ': 37.20,'FB': 10.75}
  8. Output:
  9. {'AAPL': 612.78, 'IBM': 205.55}'''
  10. ......................................
  11. def create_new_dictionary(prices):
  12. new_dict={}
  13. for key,val in prices.items():
  14. if val>200:
  15. new_dict[key]=val
  16. return new_dict
  17. prices = { 'ACME': 45.23,'AAPL': 612.78,'IBM': 205.55,'HPQ': 37.20,'FB': 10.75}
  18. print(create_new_dictionary(prices))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement