350-401 · Question #429
Refer to the exhibit. What is achieved when this Python script is executed?
The correct answer is D. Each device that is looped through in the devices.txt file is put into its own dictionary that is. The Python script processes each device entry from the devices.txt file and organizes each device's attributes into its own dictionary.
Question
Refer to the exhibit. What is achieved when this Python script is executed?
Exhibits
Options
- AAll devices that are looped through in the devices.txt file are put into a list that is appended to the
- BAll devices that are looped through in the devices.txt file are put into a single dictionary that is
- CEach device that is looped through in the devices.txt file is put into its own list that is appended to
- DEach device that is looped through in the devices.txt file is put into its own dictionary that is
How the community answered
(22 responses)- A5% (1)
- B14% (3)
- C5% (1)
- D77% (17)
Why each option
The Python script processes each device entry from the `devices.txt` file and organizes each device's attributes into its own dictionary.
This option suggests that all devices are consolidated into a single list without specifying the structured nature of each device's data, which is less flexible and descriptive than using dictionaries for device attributes.
Putting all devices into a single dictionary typically implies that each device is identified by a unique key within that dictionary (e.g., device name as key), which is different from 'each device ... put into its own dictionary'.
Storing each device's attributes in its own list (e.g., `['hostname', 'ip', 'os']`) is less descriptive and harder to access by specific attribute names compared to using a dictionary with meaningful keys (e.g., `{'hostname': 'R1', 'ip': '1.1.1.1'}`).
When iterating through a file where each line represents a device, it is a common and efficient Python programming practice to parse each line's data (e.g., hostname, IP address, OS type) and store these attributes as key-value pairs in a distinct dictionary for each individual device, which are then typically collected into a list of dictionaries.
Concept tested: Python list of dictionaries data structure for parsing files
Source: https://docs.python.org/3/tutorial/datastructures.html
Topics
Community Discussion
No community discussion yet for this question.

