question 80 Dictionaries & Sets · hard
Book seats from a list of requests
A small cinema stores its seat map as a dictionary from row letter to that row's seats, and each seat holds the name of whoever booked it, or None if it is free. Process booking requests in order. For each (name, seat) request, print <name>: booked <seat>, <name>: <seat> is taken by <owner> or <name>: no such seat <seat>. After the requests, print <row>: <n> free for every row, in seat-map order.
Inputs
seats, a dictionary from row letter to a dictionary from seat ID to a name or None; requests, a list of (name, seat_id) tuplesSeat IDsa seat ID starts with its row letter:
A2 is in row ANo such seatthe row doesn't exist, or the row exists but has no seat with that ID
Examplesthe starter's data books A1 and B2, refuses A2 (taken by Nora) and C4 (no row C), then prints
A: 0 free and B: 1 freeExpected output6 lines
- 1Grace: booked A1
- 2Theo: A2 is taken by Nora
- 3Iris: no such seat C4
- 4Hugo: booked B2
- 5A: 0 free
- 6B: 1 free