Making a container
Special methods let your class work with built-in syntax:
__len__forlen(p). It also makes an empty object falsy inif p:.__getitem__forp[0],p[-1]andp[1:3].__iter__forfor song in p,list(p)andenumerate(p).__contains__for"verse" in p.
The easy way is to delegate: keep a list inside and pass each call on to it. Slicing works for free because the list handles the slice object.
Even without __iter__ and __contains__, Python can loop and test in
using __getitem__ alone. Writing them is clearer and faster.
Watch the cost of __contains__: here it searches a list, which is O(n). If
the class is checked often, keep a set alongside for O(1) lookups, as the
Performance challenges show.
Run it, then make __getitem__ raise for negative indexes.