⚑ IT Wisdom Why do security engineers hate nature? Too many unknown vulnerabilities in the wild.
Skilled Practitioner
4249 XP 1751 to Expert
Objective: Use a list comprehension to extract only switch names from a mixed inventory.
Instructions

Create a file called lab4.py. Using the inventory below, use a list comprehension to build a list of switch names only. Then print the list and the total count.

inventory = [
    {"name": "sw-core-01",  "type": "switch"},
    {"name": "rtr-edge-01", "type": "router"},
    {"name": "sw-access-01","type": "switch"},
    {"name": "fw-dmz-01",   "type": "firewall"},
    {"name": "sw-access-02","type": "switch"},
]

Your output must match exactly:

['sw-core-01', 'sw-access-01', 'sw-access-02']
Total switches: 3

Run it with python3 lab4.py. Paste your output below and submit.

πŸ’‘ Show Hint
List comprehension: switches = [d["name"] for d in inventory if d["type"] == "switch"]. Then print(switches) and print(f"Total switches: {len(switches)}")
Paste Your Output
Next Lab β†’