200-901 Question 7
Single answerYou are working on a Python-based network automation project and need to store hierarchical data about network devices, including their hostname, IP address, and a list of VLANs they belong to. Which data structure is the most appropriate for this use case?
- A
List of strings
- B
Dictionary
- C
Set
- D
Tuple
Show answer and explanation
Correct answer: B
Explanation
For storing hierarchical data about network devices, such as a hostname, IP address, and VLANs, a dictionary is the most appropriate Python data structure. Dictionaries allow you to organize data in key-value pairs, making it easy to retrieve and manipulate the specific attributes of each device. Other data structures like lists, sets, and tuples do not provide the required flexibility or organization for this use case.
- A. Incorrect.
A list of strings can only hold ordered data and does not provide a way to organize hierarchical data with key-value pairs for the hostname, IP, and VLANs.
- B. Correct.
A dictionary is the most suitable data structure for this use case because it allows you to store and organize hierarchical data using key-value pairs, making it easy to associate hostnames with IP addresses and VLANs.
- C. Incorrect.
A set is unordered and only holds unique items, which is not suitable for storing structured, hierarchical data.
- D. Incorrect.
A tuple is immutable and is better suited for fixed collections of data. It does not provide the flexibility to handle hierarchical, key-value pair data.