Parallel 1-D Arrays
Parallel arrays are two or more arrays that store related data in the same order. Each item at a specific index in one array is linked to the items at the same index in the other arrays.
For example:
-
One array could store names:
["Jane", "John", "Jess"] -
Another could store their ages:
[14, 16, 15]
Here, Jane is 14, John is 16, and Jess is 15 — their details are linked by their position in the arrays.
names = ["Jane", "John", "Jess"]
ages = [14, 16, 15]
for i in range(len(names)):
print(names[i], "is", ages[i], "years old.")