List Twist

mediumpy_classes

Implement ListTwist, a collections.UserList subclass with extra virtual attributes — exposed only through __getattr__ / __setattr__ (do not declare them as properties or methods):

  • reversed / R — the list reversed (a new plain list).
  • first / F — get or set the first element.
  • last / L — get or set the last element.
  • size / S — get or set the length: shrinking truncates, growing pads with None.

The shortcuts must always reflect the current contents (after append, pop, slicing, etc.).

Your solution

Edit ListTwist and run the real pytest suite in your browser — no install required. Your code is saved locally.

⌘/Ctrl + ↵

Loading the Python runtime (first run only)…

Hints

Hint 1

Subclass collections.UserList and intercept the shortcut names in __getattr__ (read) and __setattr__ (write).

Hint 2

In __setattr__, route real attributes (like 'data') to super().__setattr__; for 'size', truncate or pad self.data with None.

Stuck? Try these first

mediumCustom Range