Lists, shared collections and structured results
Build reusable ID lists, find common students, unpack first and last elements, explore words and shopping items, and keep identities in pairs and triples. Build on Weeks 1–4 and keep useful results for the next computation.
Study sections
Follow the order or choose a sectionRemember a collection without removing the cards
Earlier, one variable held a count, a sum or a maximum. Now we want to remember several students together: everyone from Chennai, every…
02Lists keep order, repeats and an empty starting point
A list is a sequence written inside square brackets, with commas between its elements. [1,13,2] has three elements. ["Monday","school"]…
03Join lists and add one new element
In this course, ++ means list concatenation. If A = [1,13] and B = [2,17,1], A ++ B is [1,13,2,17,1]. No sorting or deduplication happe…
04Build May and Chennai lists from the course data
Begin with two empty results. Read each score card, apply the two filters independently and append the ID when a condition passes. Mont…
05foreach visits values in list order
x is the current element, not automatically a list index. In MayIDs, the first x is 3, even though it occupies the first position. The…
06Compare saved lists: overlap and difference
After building the two ID lists, we can find their common members without scanning every original field again. For each May ID x, compa…
07Collect everyone at the top three distinct mark levels
The earlier TopThreeMarks procedure finds distinct score levels. Maths has levels 97, 93 and 89; Physics 92, 91 and 88; Chemistry 97, 9…
08Who belongs to all three topper lists?
The first scan compares 4 × 6 = 24 identifier pairs. The second compares 2 × 4 = 8. Together these membership scans use 32 comparisons…
09Combine more lists in stages
For four collections A, B, C and D, one method is to intersect A with B, then the result with C, then that result with D. Another metho…
10Unpack a list into its first element and the rest
first(L) returns one element. rest(L) returns a list containing all occurrences after the first position. Neither operation means “remo…
11Check ascending marks with adjacent comparisons
Ascending here means non-decreasing: every mark is less than or equal to the next. Equality is allowed. Compare a neighbour pair, then…
12Collect nouns immediately after adjectives
Keep the word-card order. Let X = first(L) and Y = first(rest(L)). Select this neighbour pair only if X.PartOfSpeech is Adjective AND Y…
13Turn a word into a character list
A word stored as one field can be unpacked with explode into a character sequence. explode("It") gives ["I","t"]. You can now use forea…
14Count adjacent vowel pairs inside a word
Use the five-vowel convention a, e, i, o, u, ignoring case for this test. In specially, i is immediately followed by a, giving one matc…
15Unpack the other end: last and init
last(L) returns the last element. init(L) returns the list without its final position. For [3,13,23,25], last is 25 and init is [3,13,2…
16Is a word a palindrome?
A palindrome reads the same forwards and backwards. If the first and last characters differ, reject immediately. If they agree, remove…
17Keep an ID beside a property: lists of pairs
A list of marks alone loses the owners of those marks. A pair such as [3,53] keeps one identifier beside one property. A list of pairs…
18Find the maximum and remember every tied student
When a larger mark arrives, earlier candidates are no longer maximum scorers: replace their list with [ID]. When an equal mark arrives,…
19Store relationships as [ID1,ID2] pairs
The lecture first discusses similar performance in two subjects, then demonstrates the pair method for Physics alone. The explorer lets…
20Keep ID, Maths and Physics together in triples
A triple is a list of exactly three components. For [ID,Maths,Physics], first gives ID, first(rest(Triple)) gives Maths, and last gives…
21One bill item becomes one customer–shop–category triple
A bill contains several item rows. For each row, keep [Customer,Store,Category]. This produces one triple per ITEM ROW, not one per bil…
22Compare the same student’s positions in two lists
Make [ID,Maths] and [ID,Physics] lists, each sorted ascending by its mark. For a student at position i in the Maths list, find the SAME…
23Tutorial: implement length, first and last
length accepts a list and returns its occurrence count. The empty list returns 0 because no increment occurs. first returns during the…
24Tutorial: rest, init and membership
rest uses Found to skip exactly the first occurrence. init uses a one-element delay: when the second element arrives, append the rememb…
