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.
how do I make Liar a subclass of list
class list: def __init__(self,list = None,*args): self.list =  for arg in args: self.list.append(arg) def __len__(self): return len(self.list) class Liar(list): def __len__(self): super().__len__() return len(self.list) + 2 or len(self.list) - 5
Megan AmendolaTreehouse Teacher
You don't need to create your own list class. List is a python object already, so you only need to create your Liar class and make list its parent. In order to make something a parent, you just pass it into your class. Like so:
class Liar(list): pass
You have this already, which means the error is somewhere else in your code. For your method, when you call
super.__len__() you are actually already calling the
len() method. You're telling Python that when someone uses the
len() method on an instance of your Liar class, treat it the same way you treat calling
len() on a list. Your
super.__len__() then is the length.
def __len__(self): length = super().__len__() return length + 5