Python Object-Oriented Python Advanced Objects Frustration

I'm not realizing what he's really asking for! What is wrong?

Now I want you to make a subclass of list. Name it Liar.

Override the len method so that it always returns the wrong number of items in the list. For example, if a list has 5 members, the Liar class might say it has 8 or 2.

You'll probably need super() for this.

frustration.py
class Liar(list):
    def __len__(self):
        return super().__len__()

2 Answers

Omar G.
Omar G.
3,619 Points

Hello, This code passed for me

class Liar(list):
    def __len__(self):
        return super().__len__() + 3

If you need help rewatch the part of the video when he does the JavaScriptObject example with this code:

class JavaScriptObject(dict):
    def __getattribute__(self, item):
        try:
            return self[item]
        except KeyError:
            return super().__getattribute__(item)

That helped me out. Hope it helps you out too.

Kent Åsvang
Kent Åsvang
18,804 Points

Here's how I would do it:

class Liar(list):

    def __len__(self):
        return super(Liar, self).__len__() + 2

You can read up on how to use the built-in super()-function in the docs