[Tutor] Unintentionally manipulating a list
ranjan das
ranjand2005 at gmail.com
Fri Feb 25 15:49:48 CET 2011
I am facing the following problem
I have a list of the form
INPUT= [ [ ['A1-N','A2-Y','A3-N' ],['B1-Y','B2-N','B3-N' ] ], [.........] ]
and I want an output of the form (selecting only those elements which have a
Y associated with them)
OUTPUT=[ ['A2-Y', 'B1-Y'],[....] ]
I wrote the following code. Although it gives me the desired output, it
CHANGES the list INPUT
now after i run the code I get INPUT as the same as OUTPUT (which i dont
want to happen). I have used the copy function but it still is not working.
Any help or pointers is appreciated
*CODE*
from copy import copy
temp=copy( INPUT )
OUTPUT=temp
for i in range(len(temp)):
for j in range(len(temp[i])):
for k in range(len(temp[i][j])):
if temp[i][j][k][-1]=='Y':
OUTPUT[i][j]=temp[i][j][k]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110225/149e435b/attachment.html>
More information about the Tutor
mailing list