Re: Removing objects

2008-01-23 Thread programus
On Jan 23, 2:59 pm, [EMAIL PROTECTED] wrote: > I am writing a game, and it must keep a list of objects. I've been > representing this as a list, but I need an object to be able to remove > itself. It doesn't know it's own index. If I tried to make each object > keep track of it's own index, it woul

Re: Removing objects

2008-01-23 Thread Steven D'Aprano
On Wed, 23 Jan 2008 10:32:55 -0200, Eduardo O. Padoan wrote: > On Jan 23, 2008 9:55 AM, Steven D'Aprano > <[EMAIL PROTECTED]> wrote: >> For that to work, you need to give your class an __eq__ method, and >> have it match by name: >> >> # put this in MyClass >> def __eq__(self, other): >>

Re: Removing objects

2008-01-23 Thread Robert Kern
[EMAIL PROTECTED] wrote: > So, in general, is it more efficient to use a dictionary or to > override the __eq__ function? Sorry, I guess I wasn't as clear as I could be. If your classes have not overridden __eq__ or __cmp__, list.remove() should have worked just fine. If you want your objects

Re: Removing objects

2008-01-23 Thread Peter Otten
bladedpenguin wrote: > So, in general, is it more efficient to use a dictionary or to override > the __eq__ function? Rule of thumb: If you want to add/remove arbitrary objects from a collection a dictionary (or set) is always faster than a list. You may still have to override the __eq__() and

Re: Removing objects

2008-01-23 Thread Eduardo O. Padoan
On Jan 23, 2008 9:55 AM, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > For that to work, you need to give your class an __eq__ method, and have > it match by name: > > # put this in MyClass > def __eq__(self, other): > return self.name == self.other Do you mean: # put this in M

Re: Removing objects

2008-01-23 Thread bladedpenguin
On Jan 23, 2:24 am, Robert Kern <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > I am writing a game, and it must keep a list of objects. I've been > > representing this as a list, but I need an object to be able to remove > > itself. It doesn't know it's own index. If I tried to make each

Re: Removing objects

2008-01-23 Thread Steven D'Aprano
On Tue, 22 Jan 2008 22:59:07 -0800, bladedpenguin wrote: > I am writing a game, and it must keep a list of objects. I've been > representing this as a list, but I need an object to be able to remove > itself. It doesn't know it's own index. If I tried to make each object > keep track of it's own i

Re: Removing objects

2008-01-23 Thread Helmut Jarausch
[EMAIL PROTECTED] wrote: > I am writing a game, and it must keep a list of objects. I've been > representing this as a list, but I need an object to be able to remove > itself. It doesn't know it's own index. If I tried to make each object > keep track of it's own index, it would be invalidated whe

Re: Removing objects

2008-01-23 Thread Patrick Mullen
On Jan 22, 2008 10:59 PM, <[EMAIL PROTECTED]> wrote: > I am writing a game, and it must keep a list of objects. I've been > representing this as a list, but I need an object to be able to remove > itself. It doesn't know it's own index. If I tried to make each object > keep track of it's own index

Re: Removing objects

2008-01-22 Thread Asun Friere
On Jan 23, 6:16 pm, Asun Friere <[EMAIL PROTECTED]> wrote: > >>> x.pop(x.index(c)) Umm, of course you would simply use x.remove(c) ... force of (bad) habit. %/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Removing objects

2008-01-22 Thread Robert Kern
[EMAIL PROTECTED] wrote: > I am writing a game, and it must keep a list of objects. I've been > representing this as a list, but I need an object to be able to remove > itself. It doesn't know it's own index. If I tried to make each object > keep track of it's own index, it would be invalidated whe

Re: Removing objects

2008-01-22 Thread Asun Friere
On Jan 23, 5:59 pm, [EMAIL PROTECTED] wrote: > I am writing a game, and it must keep a list of objects. I've been > representing this as a list, but I need an object to be able to remove > itself. It doesn't know it's own index. If I tried to make each object > keep track of it's own index, it woul

Removing objects

2008-01-22 Thread bladedpenguin
I am writing a game, and it must keep a list of objects. I've been representing this as a list, but I need an object to be able to remove itself. It doesn't know it's own index. If I tried to make each object keep track of it's own index, it would be invalidated when any object with a lower index w

Re: Removing objects in a list via a wild card

2007-09-19 Thread Karthik Gurusamy
On Sep 19, 1:11 pm, David <[EMAIL PROTECTED]> wrote: > On 9/19/07, James Matthews <[EMAIL PROTECTED]> wrote: > > > Hi List > > > I have a list of files from my current directory: > > > import os > > > files = os.listdir(os.getcwd()) > > > Now this list also includes some files that i don't want lik

Re: Removing objects in a list via a wild card

2007-09-19 Thread David
On 9/19/07, James Matthews <[EMAIL PROTECTED]> wrote: > Hi List > > I have a list of files from my current directory: > > import os > > files = os.listdir(os.getcwd()) > > Now this list also includes some files that i don't want like my python > files... How would i remove them You can use regular

Removing objects in a list via a wild card

2007-09-19 Thread James Matthews
Hi List I have a list of files from my current directory: import os files = os.listdir(os.getcwd()) Now this list also includes some files that i don't want like my python files... How would i remove them Thanks James -- http://www.goldwatches.com/ http://www.jewelerslounge.com -- http://ma