List of Lists
matrix = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]
#how-to-access
print(matrix)
print(matrix[0]) # [1, 2, 3]
print(matrix[0][1]) # 2
print(matrix[2][2]) # 9
print(matrix)
print(matrix[0]) # [1, 2, 3]
print(matrix[0][1]) # 2
print(matrix[2][2]) # 9
List of Dictionaries
students = [{"name": "Mohan", "age": 25, "marks": 90},{"name": "Raj", "age": 24, "marks": 85},{"name": "Kumar", "age": 26, "marks": 88}]
#how-to-access
print(students)
print(students[0]) # First dictionary
print(students[0]["name"]) # Mohan
print(students[1]["marks"]) # 85
print(students)
print(students[0]) # First dictionary
print(students[0]["name"]) # Mohan
print(students[1]["marks"]) # 85
dictionary of lists
students = {"names": ["Mohan", "Raj", "Kumar"],"marks": [90, 85, 88]}
#how-to-access
print(students)
print(students["names"]) # ['Mohan', 'Raj', 'Kumar']
print(students["names"][0]) # Mohan
print(students["marks"][1]) # 85
print(students["names"]) # ['Mohan', 'Raj', 'Kumar']
print(students["names"][0]) # Mohan
print(students["marks"][1]) # 85
Dictionary of dictionaries
devices = {"router1": {"ip": "10.0.0.1","vendor": "Cisco","status": "up"},"switch1": {"ip": "10.0.0.2","vendor": "Juniper","status": "down"}}
#how-to-access
print(devices["router1"]["ip"]) # 10.0.0.1
print(devices["router2"]["vendor"]) # Juniper
print(devices["router2"]["vendor"]) # Juniper

0 Comments