Parallel arrays

Two arrays, same length, same order. Index i in one list pairs with index i in the other — so a linear search on names can look up a mark.

Programming Beginner Arrays · Linear search ~6 min
The idea

Same index, related data

Sometimes one array is not enough. You might store names in one list and marks in another. They stay in lockstep: the student at names[2] has the mark at marks[2].

That pairing is a parallel array. To look something up, use linear search on the key array, then read the other array at the same index.

TipKeep the arrays the same length. If you insert or delete in one, do the same at the same index in the other.
IdeaSearch then look up
find_mark.pyPython
result = None
for i in range(len(names)):
    if names[i] == target:
        result = marks[i]
        break
print(result)

Find "Chen" in names, store marks[i], then break and print.

Interactive

Run the simulation

Both arrays highlight the same index. Linear search walks names; the match unlocks marks[i].

Step 0 / 0
demo.pyPython
Parallel arraysdemo
Ready
Shortcuts: Space play/pause · → step · ← back · R reset
Remember

Why parallel arrays matter

One index ties related facts together without a single “record” type.

Index

Same position = same person

names[i] and marks[i] belong together. Never mix indices across the two lists.

Search

Linear search finds the key

Scan the key array (names) until you match the target, then stop — just like ordinary linear search.

Lookup

Reuse the index

Once you know i, read any parallel array at i — marks, ages, IDs, and so on.