Code Logo

Seat and Name Tuples

Published at22 Apr 2026
Python Data Structures Easy 0 views
Like0

A classroom assistant receives a list of student names in seating order and needs to prepare a compact seating record for the teacher. Instead of storing the seat number and the student name in separate places, the teacher wants each seat assignment represented as one pair.

Your task is to return a list of tuples in the form (seat_number, name). Seat numbering starts from 1, so the first student in the list belongs to seat 1, the second student belongs to seat 2, and so on.

For example, if the students are ["Ayu", "Bima", "Cici"], the answer should be [(1, "Ayu"), (2, "Bima"), (3, "Cici")]. If the input list is empty, the result should be an empty list because there are no seat assignments to build.

This is a simple exercise in using tuples as fixed-size records. Each tuple keeps two related pieces of information together: the seat number and the student name assigned to that seat.

Example Input & Output

Example 1
Input
students = ["Rani"]
Output
[(1, "Rani")]
Explanation

A one-student list produces one tuple pair.

Example 2
Input
students = ["Ayu", "Bima", "Cici"]
Output
[(1, "Ayu"), (2, "Bima"), (3, "Cici")]
Explanation

Each student is paired with the seat number matching their position in the list.

Example 3
Input
students = []
Output
[]
Explanation

No students means there are no tuples to create.

Algorithm Flow

Recommendation Algorithm Flow for Seat and Name Tuples
Recommendation Algorithm Flow for Seat and Name Tuples

Solution Approach

This problem is a good fit for tuples because each output item is a small record with exactly two parts. Once a seat number and name are paired together, that pair should stay together, and a tuple expresses that neatly.

The only extra detail is that the seat number does not come directly from the input values. It comes from the student's position in the list. Python's enumerate() is helpful here because it gives you both the position and the value while you loop.

One clean solution is:

return [(seat, name) for seat, name in enumerate(students, start=1)]

This comprehension reads each student name, pairs it with the current seat number, and builds the final list of tuples in one pass. Because start=1 is used, the numbering already matches the classroom rule without needing + 1 arithmetic later.

You can also write the same logic with a regular loop if you want the tuple creation to feel more explicit:

pairs = []
for seat, name in enumerate(students, start=1):
    pairs.append((seat, name))
return pairs

In both versions, the important data-structure idea is that tuples are useful when each result item has a fixed number of related fields. Here, every seat assignment always has exactly two parts, so the tuple structure is a natural match.

The runtime is O(n) because the list is processed once, and the output also uses O(n) space for the stored tuple pairs.

Best Answers

python - Approach 1
def build_seat_tuples(students):
    pairs = []
    for seat, name in enumerate(students, start=1):
        pairs.append((seat, name))
    return pairs