[Tutor] remove function
Christopher Spears
cspears2002 at yahoo.com
Thu Jul 27 06:12:39 CEST 2006
My apologies to everyone. Here is the complete code:
class PriorityQueue:
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def insert(self, item):
self.items.append(item)
def remove(self):
maxi = 0
for i in range(1, len(self.items)):
if self.items[i] > self.items[maxi]:
maxi = i
item = self.items[maxi]
self.items[maxi:maxi+1] = []
return item
--- Luke Paireepinart <rabidpoobear at gmail.com> wrote:
> Christopher Spears wrote:
> > Here is a class called PriorityQueue:
> >
> > class PriorityQueue:
> > def __init__(self):
> > self.items = []
> >
> > def isEmpty(self):
> > return self.items == []
> >
> > def insert(self, item):
> > self.items.append(item)
> >
> > def remove(self):
> > maxi = 0
> > for i in range(1, len(self.items)):
> > if self.items[i] > self.items[maxi]:
> > maxi = i
> > item = self.items[maxi]
> >
> > return item
> >
> > My question concerns the remove function. The
> > function returns the maximum value. However, I'm
> > curious about
> > self.items[maxi:maxi+1] = []. I understand that
> the
> > programmer wants to remove self.items[maxi]. Why
> > would he or she want to remove that value and the
> one
> > next to it (maxi+1)? Or am I misunderstanding
> > self.items[maxi:maxi+1] = [] ?
> >
> I don't see the line 'self.items[maxi:maxi+1] = []'
> anywhere in the
> above code.
> In fact, I don't see any list slicing taking place
> at all.
>
> > As an aside, I can't figure out how to respond to
> > topics on this list.
> >
> >
> either hit 'reply-all' in your message or change the
> 'to:'
> line from whatever the recipient's address is to
> 'tutor at python.org'
> (you can also cc. to 'tutor at python.org' but this is
> what will
> happen when you 'reply-all' anyway.)
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
"I'm the last person to pretend that I'm a radio. I'd rather go out and be a color television set."
-David Bowie
"Who dares wins"
-British military motto
"I generally know what I'm doing."
-Buster Keaton
More information about the Tutor
mailing list