list manipulation with list.pop[i]
question: i have a list of points, a list vectors and a list of angles. Say i put all if them in one nested list:
List = 
I then send each nested list to a different definition in order to be evaluated and depending on different if conditions some slots are moved to new lists.
the new lists can be returned from the definition and appended to the original Group as such
But at the same time I want to use the command list.pop(i) in order to remove the elements moved from the original List at index  because it is important to keep everything in the original "List" slots and only append more on the way (until all elements basically are dropped, List has only empty slots and script ends)
I'm a bit confused though with the List.pop(i). If you start removing elements of a list at 'i' location during an 'for i in List' loop won't that confuse the loop since the list would be getting smaller all the time and then the index will get out of range?
any suggestions on how to work through this welcome
is the right syntax
yes that's the correct syntax, my mistake, still on vbscript mode.
but still my question is further down in the thread, regarding the index.pop(i) command, if you could check it out.
Doing list.pop(i) while iterating with index over a list ist not a good idea. can be very confusing.
You could replace an item in your list with "None" instead of Pop(). then your indices stay correct.
Are you aware that python list are always passed by reference?
That means if you pass a list to a function and change it there the original list wil change too.
does this help ?
Also, as a sort of side note:
list.pop(i) actually returns the element with the index i. If you simply want to permanently delete/remove an item from a list you could use the del statement: http://docs.python.org/tutorial/data...-del-statement
But as Goswin says, be careful when doing these kind of things.
Last edited by AHD; 10-09-2012 at 09:34 PM.
Tags for this Thread