On 12/13/2009 4:36 AM Grigor Kolev said...
<snip>
Your __init__ looks OK. All the other methods return either self.list
or (with sort and append) return None because you've reassigned
self.list to the return value of self.list.sort() and
self.list.append()(both sort and append methods change the object in
place and return None -- which you've then assigned to self.list)
I've added comment lines below that describe what I would expect each
method to do. You'll need to write python code to perform each
description. I've completed one to get you started.
I'd advise you to revisit the tutorial and refresh your working
knowledge of core python. Magic methods might a bit advanced.
Emile
My answer is:
class MyList ():
def __init__(self, value=[]):
self.list=[]
for i in value:
self.list.append(i)
def __add__(self , other):
# add other to self.list
# return self.list += other
return self.list
def __mul__(self , other):
# return the result of multiplying self.list by other
return self .list
def __delitem__(self , other):
# delete item other from self.list
return self .list
def __geritem__(self , other):
# return self.list's other item
return self.list
def __repeat__(self , other):
# ?? maybe repr?
return self.list
def sort(self ):
# sort self.list in place
self.list = self.list.sort()
return self.list
def append(self , other):
# append item other to self.list
self.list=self.list.append(other)
return self.list
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor