Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAnthony Prunsky
Front End Web Development Techdegree Student 8,725 PointsI'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.
class Liar(list):
def __len__(self):
return super().__len__()
2 Answers
Omar G.
3,620 PointsHello, 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
18,823 PointsHere'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