Python SortedList error

Hi, everyone! I have almost ended the Inheritance and Polymorphism lesson.
At the resume, you’re asked to create a SortedList class, which I did but it gives me a big error. When I try to print the list, it gives me an empty one in any case.
Here’s the code:

I expected to get [4, 58, 1, 92], why I do not?

Look at your __init__ definition. That’s not going to give you your desired result, I think.

1 Like

Well I don’t know why, if I try to print(self) inside of the method the values are right in place

I meant, you declare self twice there.

1 Like

Oh I know, I was just trying something else, but also if I delete the first declaration, it’s all the same (yeah that was pretty stupid thinking about that)

For the __init__ method, take a look at your arguments.

You might not need two arguments.

The bigger question is why you would make it a class SortedList? This is in the realm of functions I think… (I could be missing something)

@franzhunter Sure! Just asking because the point of classes really veers into the semantic conception of why things are grouped the way they are.

What you are probably looking for, try to work it out before looking

Screen Shot 2020-07-14 at 6.21.05 PM

Screen Shot 2020-07-14 at 6.22.07 PM

2 Likes

It is a recap exercise at the end of the lesson and I’m just testing it

Ok I’m trying something but I still don’t get it

Oh okay understood!
I thought about that but I was just trying to not use any extra value in the SortedList class but seems to me that it is impossible to work it out
I will do as you showed me, thanks for your time! :slight_smile:

2 Likes

No problem! I think the reason why it was confusing is that you’re trying to make it behave like a function (which it can, it’s just not great at it). Normally, those self.values sit there and often have getters and setters.

Always happy to dig in to the finer nuances of python though :slight_smile:

1 Like

Yes, definitely haha
Thank you so much!