I'm really confused at the moment. I'm not looking for anyone to give me the answers, but if you could at least give hints on what i need to do in each method, i'll be happy!! FYI, one of the main things that's confusing me is that i'm not allowed to use any built in methods. Only can use the index operator [], the splice operator [:], the + operator for list concatenation, and the len function. I've attempted to begin doing the few that i know, but i'm sure they're not correct.
I tried explaining what each method is supposed to do the best that i can:
class SortedList:
def __init__(self):
"""
Creates an empty list
"""
self.L = []
def insert(self, item):
"""
Inserts new item into some sorted list, entering the item in
the corrected (Sorted) posistion in the list.
"""
self.L.append(item)
def remove(self):
"""
Removes an item from a sorted list. If item isn't in list
List remains unchanged.
"""
new_list = []
for item in self.L:
if item not in new_list:
new_list.append(item)
return new_list
def size(self):
"""
Method returns the number of occurrences of a given item in
a sorted list
"""
return len(self.L)
def count(self):
"""
Method returns the number of occurrences of a given item in a
sorted list
"""
def belongs(self):
"""
Method returns True if a given item belongs to the sorted list
and False otherwise.
"""
if i in self.L:
return True
else:
False
def __str__(self):
"""
Method returns a printable version of the sorted list, which is
a string containing the elements of the sorted list, surrounded by
square braces.
"""
s1 = "List: " + str(self.L)
def __add__(self):
"""
Method overloads the + operator and returns the sum of two sorted
lists.
"""
def __mul__(self):
"""
Method overloads the * operator and returns the product of a sorted
list and a positive interger.
"""