Problems retrieving items from a list using a reference rather than an integer - can you help?

Rogue9 lol at lolmc.com
Thu Jul 17 11:05:15 EDT 2003


After reviewing my question I realised that I should have posted the short
piece of real code I'm working on and not tried to write some pseudo-code
to illustrate the problem I'm having.Therefore I have printed the listing
below which is quite short and hopefully won't annoy too many peopleabout
the length of my post.

To reiterate:
The masterList holds the results for the UK lottery in the form
[[1,'1994-10-19',3,14,16,23,34,43,2,3,'ARTHUR',234]...] and there are 792
results in the list. The skipFreqList holds the count of skipped draws
between when a certain ball was drawn i.e if ball one was drawn in draw
one and then not again till draw 10 the list would look like this
[['Ball1',0,1,2,3,4,5,6,7,8,9,0......],['Ball2,1,2,0,1,2,3,4,5,0,0]....['Ball49',1,0,1,2,3,4,5,6,7,8]].Each
item in the skipFreqList will be 1 item longer than the masterList length
as each one starts with a string descriptor.

So,what this code is supposed to do is to retrieve each draw from the
masterList and pick the ball data from the result then for each ball index
through to that balls skip frequency list e.g.r1 = skipFreqList[b1-1](the
one is taken away from the ball value as the list starts at position 0 for
indexing as I'm sure you know).Now we use the draw number to find the
specific skip frequency value for that ball in that draw e.g.skip1 =
r1[draw] and this is where it all goes wrong in that a value of zero is
always returned rather than the value at the index position equal to the
value of the draw variable. However,if I substitute an integer for draw in
the same line e.g.skip1 = r1[10]then I always get the correct returned
value! Can anyone please help with this please - it's driving menuts
trying to figure out where I'm going wrong?

Thanks for your time and effort,
Lol McBride

import cPickle
import unittest
import oop_lb.reports.AllDrawsReport
import oop_lb.process.DrawLoop

class AllDrawsReportTest(unittest.TestCase):

    def test1(self):
# Initialise variables
        f=open('/home/lol/disk/python/lotto/dat/masterList.lb','r')
        masterList = cPickle.load(f)
        f.close()
        f=open('/home/lol/disk/python/lotto/dat/skipFreqList.lb','r')
        skipFreqList = cPickle.load(f)
        f.close()
        print skipFreqList
        draw = 1
        while 1:
            if draw == 300:# limited to 300 whilst debugging
                break
            x = masterList[draw-1]
            print draw,x
# Now we must write the skip frequency data into the table
            b1 = x[2]
            b2 = x[3]
            b3 = x[4]
            b4 = x[5]
            b5 = x[6]
            b6 = x[7]
            print b1,b2,b3,b4,b5,b6
            r1 = skipFreqList[b1-1]
            r2 = skipFreqList[b2-1]
            r3 = skipFreqList[b3-1]
            r4 = skipFreqList[b4-1]
            r5 = skipFreqList[b5-1]
            r6 = skipFreqList[b6-1]
            print r1,r2,r3,r4,r5,r6
	    skip1 = r1[draw]
            print skip1
            draw = draw+1
        return


if __name__ == '__main__':
    unittest.main()




More information about the Python-list mailing list