Bite 158. Subclass the list built-in

In this Bite you will complete IntList, a subclass of list, which should be able to do the following:

>>> from intlist import IntList
>>> mylist = IntList([1, 3, 5])
>>> mylist.mean
3
>>> mylist.median
3
>>> mylist.append(7)
>>> mylist.append(1.0)
>>> mylist.mean
3.4
>>> mylist.median
3
>>> mylist.append('a')
...
TypeError
>>> mylist.append([2, 3])
>>> mylist.append([2, 'a'])
...
TypeError
>>> mylist += [1]
>>> mylist += [1, 'a']
...
TypeError

As you see this special list is enriched with mean and median properties, and is restricted to int values only, be it as appended individually or as list of ints. Apart from overriding append, you'll also need to tweak the __add__ and __iadd__ (operator overloading) dunder methods here.

Enjoy and keep calm and code more Python!

9 out of 9 users completed this Bite.
Will you be Pythonista #10 to crack this Bite?
Average Bite difficulty 1-10 rating: 5.0
» Up for a challenge? 💪

Github login button
We use Python 3.7