SECTION 01 / 24

Remember a collection without removing the cards

2 min read

Earlier, one variable held a count, a sum or a maximum. Now we want to remember several students together: everyone from Chennai, everyone born in May, or everyone sharing the maximum Physics mark. Creating Student1, Student2 and so on is awkward because we do not know how many matches there will be. A single list variable can hold the whole collection.

Two lists can refer to the same original records, like two readers keeping different bookmarks in one book.
Two lists can refer to the same original records, like two readers keeping different bookmarks in one book.

Physically pulling out all May cards creates a problem when we also need the Chennai cards. Some students belong to both groups. Instead, keep references to the records. The lecture calls them bookmarks. Several collections can point to the same card without taking ownership of it or disturbing its order.

Our website represents those references by CardNo values and uses a lookup to display the record. An ID is not the same thing as a row position. A bare written number does not magically locate a physical card: the bookmark, index or lookup supplies that connection. Moving a row must not change its identity.

Keep the source records available. A compact list of IDs is useful for membership and overlap, but you need the source lookup again to recover a student’s name, birthday or marks. Reusing references avoids copying an entire record into every result.

Try it yourself

Can one student appear in both the May and Chennai collections?

Show explained answer

Yes. Rida (#3) and Geeta (#25) do. Two references can point to one original record.

Try it yourself

Does CardNo 25 always mean the 26th row on screen?

Show explained answer

No. Sorting or filtering changes row positions. CardNo remains the identifier attached to that student.

Try it yourself

What is lost if you remember only “8 students from Chennai”?

Show explained answer

The count tells how many, but not which students. A list of IDs preserves membership so later tasks can reuse it.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑