5.1.8 Inspecting Values with values()

Unit: Unit 5: Dictionaries and Sets • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Extract and aggregate values from a pricing dictionary
cart_prices = {
    "keyboard": 89.99,
    "mouse": 29.99,
    "monitor": 249.50,
    "usb_hub": 18.00
}

# 1. Retrieve the dict_values view
prices = cart_prices.values()

# 2. Compute aggregate statistics directly on values
total_cart_value = sum(prices)
most_expensive = max(prices)
cheapest_item = min(prices)

print(f"Total: ${total_cart_value:.2f}")
print(f"Max Item: ${most_expensive:.2f} | Min Item: ${cheapest_item:.2f}")
Open in Live Interactive Python Sandbox →