QP School

Full Version: Dictionary views in Python 3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
my_dict = {'a': 1, 'b': 2, 'c': 3}

# Dictionary view for keys
keys_view = my_dict.keys()
print(keys_view)  # Output: dict_keys(['a', 'b', 'c'])

# Dictionary view for values
values_view = my_dict.values()
print(values_view)  # Output: dict_values([1, 2, 3])

# Dictionary view for items (key-value pairs)
items_view = my_dict.items()
print(items_view)  # Output: dict_items([('a', 1), ('b', 2), ('c', 3)])