Python 41 Programming Tutorial - Min, Max, and Sorting Dictionaries

stocks = {
    'GOOG': 520.84,
    'FB': 76.95,
    'YHOO': 39.28,
    'AMZN': 306.21,
    'AAPL': 99.76
}

min_price = min(zip(stocks.values(), stocks.keys()))
print(min_price)

max_price = max(zip(stocks.values(), stocks.keys()))
print(max_price)

stocks_sorted = sorted(zip(stocks.values(), stocks.keys()))
print(stocks_sorted)

Post a Reply

你可能感兴趣的:(Python 41 Programming Tutorial - Min, Max, and Sorting Dictionaries)