Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary views in Python 3
#1
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)])
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Backward Incompatibility in Python 3 Qomplainerz 0 878 07-25-2023, 10:40 AM
Last Post: Qomplainerz
  Async/Await in Python 3 Qomplainerz 0 351 07-25-2023, 10:39 AM
Last Post: Qomplainerz
  Keyword-Only Arguments in Python 3 Qomplainerz 0 334 07-25-2023, 10:39 AM
Last Post: Qomplainerz
  Type Annotations in Python 3 Qomplainerz 0 356 07-25-2023, 10:38 AM
Last Post: Qomplainerz
  Print formatting in Python 3 Qomplainerz 0 345 07-25-2023, 10:38 AM
Last Post: Qomplainerz
  Syntax changes in Python 3 Qomplainerz 0 370 07-25-2023, 10:37 AM
Last Post: Qomplainerz
  input() function in Python 3 Qomplainerz 0 362 07-25-2023, 10:37 AM
Last Post: Qomplainerz
  range() function in Python 3 Qomplainerz 0 359 07-25-2023, 10:37 AM
Last Post: Qomplainerz
  Integer division in Python 3 Qomplainerz 0 323 07-25-2023, 10:36 AM
Last Post: Qomplainerz
  Unicode support in Python 3 Qomplainerz 0 347 07-25-2023, 10:36 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 5 Guest(s)