SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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))
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top