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 trial

Python Object-Oriented Python Advanced Objects Frustration

Help in frustration challenge

Hello,

I am having trouble with this task. I watched the previous videos and tried to construct the code in a way that I think does what the task wants me to do.

I am really not sure what I am doing wrong and could use some hints and guidance.

Thank you in advance.

frustration.py
class Liar(list):
    def __len__(self):
        super().__len__()
        for _ in self:
            return len(self) + 1

3 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya Taejooncho! All ya have to do is call "super()" on "len" of parent class "list" and add any number to it and return it. So yeah you dont need a "for" loop for that.

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

Hello Ari Misha! Thank you for your help. May I ask why? Is it because len function already does what my for loop is doing?

Ari Misha
Ari Misha
19,323 Points

Hiya! And Nope thats coz the challenge asked ya to override len() method and return anything other than the correct value for the len method. Thats what i added 5. You can add or subtract any number to return value of len(). And what you were doing wasnt even related to the challenge was askin'. (:

Hey thanks again!

I did not have the question about the adding part. I wanted to know why you did not have the for loop like I did.

You are returning just one number: the length of the Liar subclass. So there is no need to iterate over the list and add 1 to each element. The only thing that needs to be changed is the length of the list.