nerdexam
CompTIA

PT0-002 · Question #539

Which of the following Python data structures is the best way to store a group of key-value pair objects?

The correct answer is D. Dictionaries. Python dictionaries (dict) are the native data structure designed specifically for storing key-value pairs. Each entry consists of a unique key mapped to a value, enabling fast O(1) average-time lookups by key. For example: {'username': 'admin', 'port': 443}. Arrays (A) and…

Tools and Code Analysis

Question

Which of the following Python data structures is the best way to store a group of key-value pair objects?

Options

  • AArrays
  • BLists
  • CTrees
  • DDictionaries

How the community answered

(26 responses)
  • B
    4% (1)
  • C
    4% (1)
  • D
    92% (24)

Explanation

Python dictionaries (dict) are the native data structure designed specifically for storing key-value pairs. Each entry consists of a unique key mapped to a value, enabling fast O(1) average-time lookups by key. For example: {'username': 'admin', 'port': 443}. Arrays (A) and Lists (B) store ordered sequences of values indexed by integer position - not arbitrary keys. Trees (C) are hierarchical data structures used for sorted data or hierarchical relationships, not simple key-value storage. Whenever the requirement is to associate a named key with a value, dictionaries are the correct Python choice.

Topics

#Python#Data Structures#Key-Value Pairs#Programming Fundamentals

Community Discussion

No community discussion yet for this question.

Full PT0-002 Practice