Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #infytq
- '''Write a python function to create and return a new dictionary from the given dictionary(item:price).
- Given the following input, create a new dictionary with elements having price more than 200.
- prices = {'ACME': 45.23,'AAPL': 612.78, 'IBM': 205.55,'HPQ': 37.20,'FB': 10.75}
- Sample Input:
- { 'ACME': 45.23,'AAPL': 612.78, 'IBM': 205.55,'HPQ': 37.20,'FB': 10.75}
- Output:
- {'AAPL': 612.78, 'IBM': 205.55}'''
- ......................................
- def create_new_dictionary(prices):
- new_dict={}
- for key,val in prices.items():
- if val>200:
- new_dict[key]=val
- return new_dict
- prices = { 'ACME': 45.23,'AAPL': 612.78,'IBM': 205.55,'HPQ': 37.20,'FB': 10.75}
- print(create_new_dictionary(prices))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement