473,322 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

modify element of a list.

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:
if o.getDescription() == desc:
self.Objects.replace(o, n) #Replace o with n?
return
self.Objects.append(n)

It's the replace in place that I don't know how to do...

Aug 17 '06 #1
2 1775
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

Aug 17 '06 #2
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, value)
for o in self.Objects:
if o.getDescription() == desc:
self.Objects.replace(o, n) #Replace o with n?
return
self.Objects.append(n)

It's the replace in place that I don't know how to do...
There are a number of ways. I suspect the simplest would be (untested):

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)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Aug 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Konrad Den Ende | last post by:
I have a function returning a string but the problem is that the color of it is blue which suits me well for some pages but not for others. Is it possible to "feel" what the color of the background...
9
by: Carlis | last post by:
I want to make a program that, when you have the mouse on a word, that word is bold... and when you don't have the mouse on that word, the word is not bold. Excuse me for my poor English :-( But...
1
by: Jon | last post by:
Hello. I have a listbox that has about 600 or so items in. I bind it to a dataset and all is fine. However, i need to modify some of the elements colour depending on the value from the DB....
23
by: no1zson | last post by:
I have been adding buttons to my GUI to manipulate list data. I added a Delete button this morning in case I decide I no longer needed a particular element. I am now working on a modify button, in...
8
by: =?Utf-8?B?YmJn?= | last post by:
I am getting this error when I tried to modify one field inside foreach loop. public struct myStruct { public int a; public bool b; //... } private List<myStructMyStruct = new...
3
by: szimek | last post by:
Hi! Like many others before recently I've found out that firstChild works little bit differently in IE and other browsers. I've got huge app that is currently IE only and used firstChild all...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I modify the current page in a browser?...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.