Python: Emptying temporary list used in a loop without losing referenced information -


i have following kind of data, want collect 1 big list each row in big list has 1 of these below (c-d , e-f correspond second , third of these). mean lista_results[0] includes first of these , lista_results[1] second etc.

(name)      (amount-of-points) name   12 other name  19 ...         ... 

i have loop takes information other lists , adds result list. code along following lines:

lista_results = [] lista_temp = [] y in range(0,10):     x in range(0,10):         lista_temp.append(name_list[y][x], point_list[y][x])     lista_results.append(lista_temp)     #lista_temp[:] = [] 

without emptying, appended same list every time x loop finishes. is:

[0]["some name",12] [0]["other name",19] [1]["some name",12] [1]["other name",19] [1][c,1c] [1][d,2d] [2]["some name",12] [2]["other name",19] [2][c,1c] [2][d,2d] [2][e,1e] [2][f,2f] ... 

but want is:

[0]["some name",12] [0]["other name",19] [1][c,1c] [1][d,2d] [2][e,1e] [2][f,2f] ... 

which mean have somehow empty lista_temp after appending lista_results. when empty (using #lista_temp[:] = []), seems parts appended lista_results emptied, or @ least "indexerror" when trying print out lista_results[0][0][0]. assume bot reference same list , emptying either empties other.

i tried lista_newtemp=lista_temp , got indexerror after emptying lista_temp.

what way empty lista_temp after append without losing previous information appended?

(also, first question here, hope did well. hope problem explanation clear. feedback appreciated!)

it's hard tell output samples data you're working on, sounds me don't want empty list create new list next iteration. like:

lista_results = [] y in range(0,10):     lista_temp = []     # have new lista_temp every y     x in range(0,10):         lista_temp.append(something_here)     lista_results.append(lista_temp) 

the behaviour see because python not make implicit copies. every lista_temp appended lista_results same object, in turn kept changing.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -