Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Problems retrieving items from a list using a reference rather than an integer - can you help? (http://www.velocityreviews.com/forums/t319788-problems-retrieving-items-from-a-list-using-a-reference-rather-than-an-integer-can-you-help.html)

 Rogue9 07-16-2003 09:57 PM

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

Hi,
I´m trying to retrieve an item from a list using a reference called
´draw´' (which is an integer from 1 to 792 in a while loop) using:-

draw = 1
while 1:
if draw == 792:
break
b1 = someOtherList[draw-1]
r1 = b1[draw]
draw = draw+1

However,the item I expect is not being retrieved i.e. a zero is the result
of the retrieval rather than the integer in the list I was expecting.
Furthermore,when I substitute an integer for draw e.g. r1 = b1[12],I
do get the expected result.
Can anyone enlighten me as to why and how to get over this please?
Thanks
Lol McBride

 Bengt Richter 07-17-2003 05:56 AM

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

On Wed, 16 Jul 2003 22:57:16 +0100, "Rogue9" <lol@lolmc.com> wrote:

>Hi,
>I´m trying to retrieve an item from a list using a reference called
>´draw´' (which is an integer from 1 to 792 in a while loop) using:-
>
>draw = 1
>while 1:
> if draw == 792:
> break
> b1 = someOtherList[draw-1]
> r1 = b1[draw]
> draw = draw+1
>
>However,the item I expect is not being retrieved i.e. a zero is the result
>of the retrieval rather than the integer in the list I was expecting.
>Furthermore,when I substitute an integer for draw e.g. r1 = b1[12],I
>do get the expected result.
>Can anyone enlighten me as to why and how to get over this please?

Assuming all the lists are big enough, why is not the end result of the
above loop just
b1 = someOtherList[790]
r1 = b1[791]
draw = 792
In other words, you are not showing how your code showed you what was "being retrieved."
Put in some prints to show us. Unless there are some sneaky side effects, you could as
well start draw off at e.g. 789 so there won't be too much printing ;-)
Is someOtherList a big list of lists or is it some strange indexable producing another
strange indexable when indexed?

Regards,
Bengt Richter

 Bob Gailer 07-17-2003 04:51 PM

Re: Problems retrieving items from a list using a referencerather than an integer - can you help?

At 04:05 PM 7/17/2003 +0100, Rogue9 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

[snip]
I sure hope you are not writing "yet another winning lottery number
predictor". It is a sad commentary on mathematics education when
individuals belive that one can predict the outcome of a truly random
process based on any history. I for one certainly won't support any effort

Bob Gailer
bgailer@alum.rpi.edu
303 442 2625

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003

 Bengt Richter 07-17-2003 08:05 PM

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

On Thu, 17 Jul 2003 16:05:15 +0100, "Rogue9" <lol@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')
f.close()
f=open('/home/lol/disk/python/lotto/dat/skipFreqList.lb','r')
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

 Rogue9 07-17-2003 08:57 PM

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

As I put in my reply to your personal email - I asked in the python ng for
help with a python program I was writing NOT an opinion on what I was
writing.
Not replying to the post would have been better than you pushing your
opinions on others when not asked.
When I posted I didn´t say ¨Hey guys,help me and the program I write
will guarantee you´ll win the lottery.¨ I merely asked for help with a
programming problem for a personal project - whether it is a fools errand
is my business and not for anyone else to gainsay.

On Thu, 17 Jul 2003 10:51:41 +0000, Bob Gailer wrote:

> At 04:05 PM 7/17/2003 +0100, Rogue9 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

> [snip]
> I sure hope you are not writing "yet another winning lottery number
> predictor". It is a sad commentary on mathematics education when
> individuals belive that one can predict the outcome of a truly random
> process based on any history. I for one certainly won't support any
> effort to further mislead people.
>
> Bob Gailer
> bgailer@alum.rpi.edu
> 303 442 2625
>
> ---
> Outgoing mail is certified Virus Free. Checked by AVG anti-virus system
> (http://www.grisoft.com). Version: 6.0.500 / Virus Database: 298 -
> Release Date: 7/10/2003

 John Hunter 07-17-2003 09:55 PM

Re: Problems retrieving items from a list using a reference ratherthan an integer - can you help?

>>>>> "Bob" == Bob Gailer <bgailer@alum.rpi.edu> writes:

Bob> [snip] I sure hope you are not writing "yet another winning
Bob> lottery number predictor". It is a sad commentary on
Bob> mathematics education when individuals belive that one can
Bob> predict the outcome of a truly random process based on any
Bob> history. I for one certainly won't support any effort to

Granted, but this reminds me of the excellent story when 2 chaos
mathematicians went to the Montreal Casino to try and figure out the
pattern of the random number generator for the Keno game. After some
time, they noticed that the numbers were simply repeating. Apparently
there was a defect in the hardware, and when the machines were
rebooted, they started with the same random seed. he won \$600,000 in
three consecutive jackpots.

So looking for patterns in the outputs of RNGs is not total folly. Of
course RNGs are not "truly random".....

JDH

 Steven Taschuk 07-18-2003 12:04 AM

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

Quoth Rogue9:
> 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.

Excellent!

I'd also like to see a trimmed-down example of the input data
which causes the unexpected output. If you don't mind, extract
from your pickle files sublists of, say, five or ten elements,
change the code to set masterList and skipFreqList directly to
those sublists and verify that the problem still occurs, and post
that, along with what output you see and what output you expect.

--
Steven Taschuk "[W]e must be very careful when we give advice
staschuk@telusplanet.net to younger people: sometimes they follow it!"
-- "The Humble Programmer", Edsger Dijkstra

 Terry Reedy 07-18-2003 12:33 AM

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

"Rogue9" <lol@lolmc.com> wrote in message news:3f15ca92@shknews01...
> Hi,
> I´m trying to retrieve an item from a list using a reference called
> ´draw´' (which is an integer from 1 to 792 in a while loop) using:-

'draw' is a name (or maybe a variable) bound to a succession of
integers. Calling it a reference is not generally helpful and may

> draw = 1
> while 1:
> if draw == 792:
> break
> b1 = someOtherList[draw-1]
> r1 = b1[draw]
> draw = draw+1

For newsgroup postings, spaces generally work better than tabs.

To make it easier to answer such questions, make your lists short
enough (say len() == 3) to post. Make sure you copy and paste the
actual code executed. Then copy and past the actual result and
explain what you wanted or expected that would be different.

Terry J. Reedy

 Dennis Lee Bieber 07-18-2003 06:04 AM

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

Rogue9 fed this fish to the penguins on Wednesday 16 July 2003 02:57 pm:

> draw = 1
> while 1:
> if draw == 792:
> break

Assuming you don't want to use a for loop...

draw = 1
while draw < 792:

> b1 = someOtherList[draw-1]
> r1 = b1[draw]

Well a literal reading of this would mean that you have a list with
791 elements (0..790), and EACH element is a list one element longer
than its position in the original list..

Note that you are using the same variable to index into both lists.

I doubt that this is what you want.

--
> ================================================== ============ <
> wlfraed@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed@dm.net | Bestiaria Support Staff <
> ================================================== ============ <

 Dennis Lee Bieber 07-18-2003 07:13 AM

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

Rogue9 fed this fish to the penguins on Thursday 17 July 2003 08:05 am:

Ignoring all the pickle stuff...

Question, does the skip list go back to 0 /on/ the draw that the ball
was picked (meaning that the skip list is counting how many draws it
was NOT picked -- and would imply that you would ALWAYS see a 0).

> draw = 1
> while 1:
> if draw == 300:# limited to 300 whilst debugging
> break
> x = masterList[draw-1]
> print draw,x

Okay, you've just pull a sublist of the form

[1,'1994-10-19',3,14,16,23,34,43,2,3,'ARTHUR',234]

> # Now we must write the skip frequency data into the table
> b1 = x[2]

b1 = 3, if I use your sample sublist...

> b2 = x[3]
> b3 = x[4]
> b4 = x[5]
> b5 = x[6]
> b6 = x[7]

What is all that supposed to represent? b1-b6 are taking on the value
of the /ball/ that shows up in that position. Why bother, you can put
x[?] at each use of b? below.

> print b1,b2,b3,b4,b5,b6
> r1 = skipFreqList[b1-1]

r1 = ['Ball3',....]

> r2 = skipFreqList[b2-1]
> r3 = skipFreqList[b3-1]
> r4 = skipFreqList[b4-1]
> r5 = skipFreqList[b5-1]
> r6 = skipFreqList[b6-1]

Okay, the r1..r6 should now be the skip LIST for whatever ball# is in
the b1..b6.

But where do you index /into/ those lists for the specific skip value.
IE,

s1 = r1[draw]

> print r1,r2,r3,r4,r5,r6
> skip1 = r1[draw]
> print skip1
> draw = draw+1
> return
>
>
> if __name__ == '__main__':
> unittest.main()

# watch out for line wrapping in the news client!

masterList = [
[1, '1994-10-19', 3, 14, 16, 23, 34, 43, 2, 3, 'Arthur', 234],
[2, '1994-10-28', 10, 14, 23, 25, 30, 49, 3, 4, 'What are those
last', 8378],
[3, '1994-11-10', 3, 15, 23, 24, 29, 40, 4, 5, 'Huh?', 838] ]

skipFreqList = [ #How do you initialize a skip for a never
drawn
['Ball1', -1, -1, -1], #first time
['Ball2', -1, -1, -1],
['Ball3', 0, 1, 0],
['Ball4', -1, -1, -1],
['Ball5', -1, -1, -1],
['Ball6', -1, -1, -1],
['Ball7', -1, -1, -1],
['Ball8', -1, -1, -1],
['Ball9', -1, -1, -1],
['Ball10', -1, 0, 1],
['Ball11', -1, -1, -1],
['Ball12', -1, -1, -1],
['Ball13', -1, -1, -1],
['Ball14', 0, 0, 1],
['Ball15', -1, -1, 0],
['Ball16', 0, 1, 2],
['Ball17', -1, -1, -1],
['Ball18', -1, -1, -1],
['Ball19', -1, -1, -1],
['Ball20', -1, -1, -1],
['Ball21', -1, -1, -1],
['Ball22', -1, -1, -1],
['Ball23', 0, 0, 0],
['Ball24', -1, -1, 0],
['Ball25', -1, 0, 1],
['Ball26', -1, -1, -1],
['Ball27', -1, -1, -1],
['Ball28', -1, -1, -1],
['Ball29', -1, -1, 0],
['Ball30', -1, 0, 1],
['Ball31', -1, -1, -1],
['Ball32', -1, -1, -1],
['Ball33', -1, -1, -1],
['Ball34', 0, 1, 2],
['Ball35', -1, -1, -1],
['Ball36', -1, -1, -1],
['Ball37', -1, -1, -1],
['Ball38', -1, -1, -1],
['Ball39', -1, -1, -1],
['Ball40', -1, -1, 0],
['Ball41', -1, -1, -1],
['Ball42', -1, -1, -1],
['Ball43', 0, 1, 2],
['Ball44', -1, -1, -1],
['Ball45', -1, -1, -1],
['Ball46', -1, -1, -1],
['Ball47', -1, -1, -1],
['Ball48', -1, -1, -1],
['Ball49', -1, 0, 1] ]

print "skip values of '-1' signify this is the first time"
print "that this ball has been drawn"
print ""

for bnum in masterList[0][2:8]:
print "%8s" % bnum,
print " ball"
for x in range(2, 8):
print "%8s" % -1,
print " skips"
print ""

for i in xrange(1,len(masterList)): #skip first draw, there are no
skips
draw = masterList[i]
for bnum in draw[2:8]:
print "%8s" % bnum,
print " ball"
for bnum in draw[2:8]:
print "%8s" % skipFreqList[bnum-1][i],
print " skips"
print ""

--
> ================================================== ============ <
> wlfraed@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed@dm.net | Bestiaria Support Staff <
> ================================================== ============ <