Python Object-Oriented Python Advanced Objects Frustration

What is wrong with my code please?

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.
class Liar(list):
    def __len__(self, list1):
        return (len(list1) - 2)

1 Answer

Alex Koumparos
Alex Koumparos
Python Web Development Treehouse Moderator 33,371 Points

Hi Ammar,

You've got the right general idea but the initialiser for len() doesn't take a value (it's operating on self, which is the list instance). This means you need to get rid of the list1 parameter.

Instead of working with list1, you will be working with the value that super's initialiser returns.

Hope that makes sense



Thank you so much Alex! Changed my code based on your comments and now passes the check!