Re: modify element of a list.

2006-08-17 Thread Steve Holden
KraftDiner wrote: > Hi I have a list of Ojbects... I want to change one of the objects in > the list for a new object > How do I replace an existing object with a new one and maintain the > list order.. > > This is what I have... > > def setAttribute(self, desc, value): >n = anObject(desc

Re: modify element of a list.

2006-08-17 Thread Pierre Quentel
Hi, The most simple is to use the index of the element in the list : def setAttribute(self, desc, value): n = anObject(desc, value) for i,o in enumerate(self.Objects): if o.getDescription() == desc: self.Objects[i] = n return self.Objects.append(n) Pierre -- h

modify element of a list.

2006-08-17 Thread KraftDiner
Hi I have a list of Ojbects... I want to change one of the objects in the list for a new object How do I replace an existing object with a new one and maintain the list order.. This is what I have... def setAttribute(self, desc, value): n = anObject(desc, value) for o in self.Objects: