runtime
264 / 500
question 264 Inheritance & Composition · easy

An inbox that isn't a list

The support team's Inbox subclasses list, so other code has started calling inbox.sort(), inbox.clear() and inbox.insert() on it. Refactor it to hold its messages instead of being a list, keeping the behaviour of receive, unread and mark_read exactly the same, and adding count() (a list's len no longer applies).

ClassInbox() holding its messages in its own list; not a list itself
Unchangedreceive(sender, subject), unread() (the unread messages' subjects, oldest first) and mark_read(index) (an IndexError for a bad index, as before)
Newcount() → how many messages there are

Loading your progress…

An inbox that isn't a list — Python practice · Runtime