Python Object-Oriented Python Advanced Objects Frustration

Noah Fields
Noah Fields
13,985 Points

Object-Oriented Python, Code Challenge: Frustration, help

I am attempting the code challenge in Object-Oriented Python known as "frustration". True to its name, this is quite a tough challenge, and it involves creating a subclass of list called "Liar" with a redefined len() command which gives the incorrect value. What I find to be problematic here is that I somehow need to get the actual len() value at some point during this program, so that I can change the number to something which I can know with certainty is not accurate. I attempted to briefly use super().len() but to no avail, perhaps due to incorrect syntax. Are there any suggestions on the proper way to get the true len() value of a given variable in such a situation?
class Liar(list):
    def __init__(self, *args, **kwargs):
        for x in self:

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 59,587 Points

There are parts to this challenge:

  • create a class Liar that is a subclass of list
  • create a __len__ method (which will override the inherited version). Only self parameter needed.
  • call the parent __len__ method use: super().__len__(self)

Post back if you need more help. Good Luck!!