[Tutor] A couple questions about lists

Brett brett42@flex.com
Fri, 27 Apr 2001 21:32:16 -1000


<html>
I had some variables I wanted to do similar operations on, so i put them
in a list and sent them through a for loop:<br>
for x in [a,b,c,d,e]:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>if
x&lt;10:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>x=x+10<br>
&nbsp;After running this the list and the variables all had the same
values, but x was equal to 15(the value of e). I<u>s there a way to
change part of a list with using it's index?</u>&nbsp; Either way, I
figured out that I could use<br>
list=[a,b,c,d,e]<br>
for x in range(0,4):<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>if
list[x]&lt;10:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>list[x]=list[x]+10<br>
But it only changed the values in the list, and didn't change the
variables.&nbsp; I<u>s there a way to make a list, or some other object,
that keeps a reference to the variable instead of just taking it's
value?<br>
<br>
</u><br>
<div>When Schrodinger's cat's away,</div>
<div>the mice may or may not play,</div>
<div>no one can tell.</div>
</html>