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
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):
>>
[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
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
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
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
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
[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
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
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
[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
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
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
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
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
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
16 matches
Mail list logo