Created
April 10, 2015 14:05
-
-
Save Averroes/62e369c7c69672027e49 to your computer and use it in GitHub Desktop.
calculating with dictionaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example.py | |
# | |
# Example of calculating with dictionaries | |
prices = { | |
'ACME': 45.23, | |
'AAPL': 612.78, | |
'IBM': 205.55, | |
'HPQ': 37.20, | |
'FB': 10.75 | |
} | |
# Find min and max price | |
min_price = min(zip(prices.values(), prices.keys())) | |
max_price = max(zip(prices.values(), prices.keys())) | |
print('min price:', min_price) | |
print('max price:', max_price) | |
print('sorted prices:') | |
prices_sorted = sorted(zip(prices.values(), prices.keys())) | |
for price, name in prices_sorted: | |
print(' ', name, price) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment