Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Advanced Objects Frustration

How do i call the list methods on Liar

How do i get the code to call the list methods on Liar and also how do I return the wrong Len

frustration.py
class Liar(list):
    def __init__(self, *args,**kwargs):
        super().__init__()
        alist = []

    def __len__(self):
        return self.alist

2 Answers

Steven Parker
Steven Parker
210,936 Points

Since you're inheriting from "list", you can call list methods by adding a "self." prefix for any you have not overridden, or a "super()." prefix for those you have.

And perhaps the easiest way to always return a wrong length is to get the correct length from the list, and then add some small fixed quantity to it.

Carlos Marin
Carlos Marin
7,997 Points

you only need to change the length of the object. remember: you are inheriting all the properties from the parent class: (list). you just need to override the way the len of the object is determined, by defining len.