Everything about loops
What are Loops
for device in devices:
if interface in device["interfaces"]:
print(f"ALERT: {device['hostname']} {interface['name']} is down")
Every look begins with for x in y:
- for kicks off the loop process
- X = a variable to temporary hold the data incoming from variable Y.
- Y = a variable, data in a list or dictionary.
list is Y = data []
dictionary is
Y = [
{
"hostname": "leaf101",
"interfaces": "eth1/1"
}
]
Basically the format is --> key:items