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.
Can I increment inside the dunder len function? Looking for some direction with the frustration.py challenge.
I'm really struggling with the instructions here. I'm not sure how to use super() here unless maybe I make a class called list, and inherit from that?
Seems like I could just increment the dunder len function and return that result. Am I on the right track here?
Thanks in advance for the help.
class Liar(list): super().__init__() def __len__(self, numlist=None): self.numlist =  if self.numlist > 0: return len(self.numlist) += 3
Steven Parker217,570 Points
You can't increment the "len" function itself ("
+="), but you can always add to the value it returns ("
Also, since you're redefining "len", to avoid a recursive infinite loop you probably want to call the parent version instead (using "
Lastly, since the object derives from "list", you won't need to create a separate "numlist". You can just use "self".
Just getting back to this and wanted to follow up. Anyone have some thoughts on my code above?
Well I passed the challenge but I don't understand what's happening in the code.
Why do we need to call the len function of the parent class using super()? Could we not override the len method to meet the needs of the challenge?
class Liar(list): def __len__(self): truth = super().__len__() return truth + 2