In my previous post, the Basket object can be iterated (for example, over a for loop). But it cannot be subscriptable:

To make it subscriptable, we refactor the original code on the right so it becomes like the one on the left:

We only need to implement these methods:

  • __getitem__(index)
  • __len__()