Hi,<br><br>I am having a very strange problem with modifying a variable in a list in my program. Here is the code:<br><br><span style="font-family: courier new,monospace;"># a list that contains dictionary objects</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">jobs = []</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">index=5</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">for each in range(index):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> jobs.append({'v':0})</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">some_function(index):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if jobs[index]['v'] == 0:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> # set it to 1</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <span style="background-color: rgb(255, 102, 102);">jobs[index]['v'] = 1</span></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <span style="background-color: rgb(153, 255, 153);">print "Set to 1"</span></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> else:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> print "Already set to 1"</span><br><br><span style="font-family: courier new,monospace;">loop():</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> index=0</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for each in range(len(jobs)):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> some_function(index)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> index +=1</span><br>
<br><br>Apparently, the jobs[index]['v'] never get updated in the some_function but the print statement afterwards get printed...<br><br>What's really surprising is that there are no errors or exceptions and my my program runs in a single thread...so i have been unable to explain this behavior. <br>
<br>Any insight would be much appreciated!<br><br>Cheers<br clear="all">Omer<br><br><br>