Lab 3 of 5
Β·
Semi-Guided
Find All Unique VLANs in an Inventory
Objective: Use a set comprehension to extract unique VLAN IDs from a device list.
Instructions
Create a file called lab3.py. Using the device list below, find all unique VLANs and print them sorted. Then print the total count.
devices = [
{"name": "sw-core-01", "vlan": 10},
{"name": "sw-access-01","vlan": 20},
{"name": "sw-access-02","vlan": 10},
{"name": "sw-access-03","vlan": 30},
{"name": "sw-access-04","vlan": 20},
]
Your output must match exactly:
[10, 20, 30]
Unique VLANs: 3
Run it with python3 lab3.py. Paste your output below and submit.
π‘ Show Hint
Use a set comprehension: vlans = {d["vlan"] for d in devices}. Then print(sorted(vlans)) to get a sorted list. len(vlans) gives the count.
Paste Your Output