Lab 2 of 5
Β·
Semi-Guided
Display a Nested Inventory with pprint
Objective: Use pprint to format a list of device dictionaries in a readable layout.
Instructions
Create a file called lab2.py. Print the inventory below using pprint with width=60, then print the total count.
inventory = [
{"name": "sw-core-01", "ip": "10.1.1.1", "site": "HQ", "vlan": 10},
{"name": "sw-access-01","ip": "10.1.1.2", "site": "HQ", "vlan": 20},
{"name": "rtr-edge-01", "ip": "10.1.1.254", "site": "HQ", "vlan": 1},
{"name": "fw-dmz-01", "ip": "10.1.2.1", "site": "DMZ", "vlan": 100},
]
Your output must match exactly:
[{'ip': '10.1.1.1', 'name': 'sw-core-01', 'site': 'HQ', 'vlan': 10},
{'ip': '10.1.1.2', 'name': 'sw-access-01', 'site': 'HQ', 'vlan': 20},
{'ip': '10.1.1.254', 'name': 'rtr-edge-01', 'site': 'HQ', 'vlan': 1},
{'ip': '10.1.2.1', 'name': 'fw-dmz-01', 'site': 'DMZ', 'vlan': 100}]
Total devices: 4
Run it with python3 lab2.py. Paste your output below and submit.
π‘ Show Hint
from pprint import pprint. Call pprint(inventory, width=60). The dict keys will appear in alphabetical order. Follow with a regular print() for the count.
Paste Your Output