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!
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
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 Parker227,141 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