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

Bengt Richter bokr at oz.net
Thu Jul 17 16:05:28 EDT 2003


On Thu, 17 Jul 2003 16:05:15 +0100, "Rogue9" <lol at lolmc.com> wrote:

>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.
I don't understand what skipFreqList really is. Do the zeroes signify that the ball was picked
as the first ball in that draw and numbers n mean it was drawn in that draw
as the (n+1)th ball? (if so why have a 9, since 8 is all the balls taken for a given draw?)
IMO a more straight-forward encoding of that info would be just the pick order of the
ball for a given draw: 1-8 for picked first-last, and zero for not picked at all.
If you use 0-7 for pick order and call it skips, and then have 8 mean skip altogether,
that might be what's happening? But then your 9 is a typo ;-)

If that's it, you'd expect to get zero about 1 in 8, but not always.

Why not just load the data interactively by typing
(or maybe you can just copy this and run it as something.py for starters
to see what we get (untested! but you should be able to fix it ;-)

====< something.py >===========================================
import cPickle
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()

#and then interactively looking at the data step by step the way you
#think the program should be looking at it.

#You can also make little interactive loops to show specific items from all the draws,
#e.g., (untested!)

def getSkip(draw, pick): # ok, index draw from 1, and picks also 1-8
    drawresult = masterList[draw-1] # draw starts with 0 from xrange
    ball = drawresult[pick+1] # picked ball
    skip = skipFreqList[ball-1][draw] # past ball name
    return (ball, skip)  # since we are talking about the first ball here, the skip is always 0?

print 'pick #1'
for draw in xrange(1,20):  # or xrange(1,len(masterList)+1): for the whole thing
    print getSkip(draw, 1), # first ball pick in any draw should get skip of 0, right??
print 

# now try second pick
print 'pick #2'
for draw in xrange(1,20):  # or xrange(1,len(masterList)+1): for the whole thing
    print getSkip(draw, 2), # 2nd ball pick in any draw should get skip of 1, right??
print 

#Or what does skipFreqList mean?
# ===================================================================

HTH

Regards,
Bengt Richter




More information about the Python-list mailing list