Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/1/calculating_with_dictionaries/example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# example.py
#
# Example of calculating with dictionaries
from operator import itemgetter

prices = {
'ACME': 45.23,
Expand All @@ -11,15 +12,15 @@
}

# Find min and max price
min_price = min(zip(prices.values(), prices.keys()))
max_price = max(zip(prices.values(), prices.keys()))
min_price = min(prices.items(), key=itemgetter(1))
max_price = max(prices.items(), key=itemgetter(1))

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:
prices_sorted = sorted(prices.items(), key=itemgetter(1))
for name, price in prices_sorted:
print(' ', name, price)