On 6/5/06, <b class="gmail_sendername">Peter Jessop</b> <<a href="mailto:pjlists@gmail.com">pjlists@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks Andre<br><br>I realise now I did not make it too clear.<br>Basically the variable names are predictable but the values aren't.</blockquote><div><br>I assumed that. I just recreated the list as you gave it because it was easy :-)
<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Maybe I should have expressed it like this<br><br>f0_n = "arbitrayValue"
<br>f0_v ="another valule"<br>f1_n="something else"<br>f1_v="etc.."<br>...<br><br>f100_n = "another value"<br>f100_v = "nexvalue"<br><br>I then wish to pass the list of 2ples as an argument to a function and
<br>thus I need the variable themselves and not the string values.</blockquote><div><br>Ok, the approach I gave you would produce instead:<br><br>data = [ ("arbitraryValue", "another valule"), ("something else", .... ]
<br><br>Why couldn't you pass this to your function? <br><br>Ok, here's another experiment...<br><br>1. I will first generate a whole bunch of arbitrary numerical values:<br>import random<br>for i in range(101):<br> print 'f%d_n = %d'%(i,
random.randint(0, 100))<br> print 'f%d_v = %d'%(i, random.randint(0, 100))<br>===<br>f0_n = 40<br>f0_v = 28<br>f1_n = 49<br>f1_v = 5<br>...<br>====================<br>2. Next, I will use the approach I gave you before, but with these values, and I will do it with a one-liner:
<br>data = '[' + ','.join(["(f%d_n, f%d_v)"%(i, i) for i in range(101)]) + ']'<br><br>big_list = eval(data)<br><br>3. Next, I will define a function that works on these values<br><br>def find_special(data):<br> for item in data:
<br> if item[0] < 10:<br> print item[1], <br><br>find_special(big_list)<br>=========<br>The result in my case turns out to be:<br>49 50 57 96 98 23 69 16 4<br>====================<br>Of course this result on its own is meaningless :-)
<br><br>Nonetheless, does this help? Or do you really, absolutely need to pass the named variables, not their values?<br><br>André<br><br><br><br><br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor
</a><br></blockquote></div><br>