473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
Jul 18 '05 #1
9 1927
On Wed, 16 Jul 2003 22:57:16 +0100, "Rogue9" <lo*@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
Jul 18 '05 #2
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
bg*****@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

Jul 18 '05 #3
On Thu, 17 Jul 2003 16:05:15 +0100, "Rogue9" <lo*@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
Jul 18 '05 #4
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
bg*****@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

Jul 18 '05 #5
>>>>> "Bob" == Bob Gailer <bg*****@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
Bob> further mislead people.

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

Jul 18 '05 #6
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
st******@telusplanet.net to younger people: sometimes they follow it!"
-- "The Humble Programmer", Edsger Dijkstra

Jul 18 '05 #7

"Rogue9" <lo*@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
someday mislead you.
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
Jul 18 '05 #8
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.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #9
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 ""

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sniper | last post by:
Hi guys I am retrieving an attachment using a web service. what would be the fastest way to download the attcahment ? WSE Attacahment or byte array or any other methods ??? tahnks in...
2
by: Cox | last post by:
Hello: My address jsmith435@cox.net is subscribed to at least the PHP General mailing list. I have for days now been trying to unsubscribe from all PHP mail lists. I have followed the...
1
by: rllioacvuher | last post by:
I need help with a program. I have implemented that following header file with an unordered list using one array, but i need to be able to use an ordered list and 2 arrays (one for the links and one...
2
nabh4u
by: nabh4u | last post by:
hi friends, i have a program where i have to sort a double linked list using merge sort. i am having problem with changing the pointers of the list, like the previous and the next pointers of a...
6
by: Suyash Upadhyay | last post by:
Hi All, As a beginner in Computer Programming, I decided to create Linked List using recursion, but I am not getting right answer. I think it is fundamentally correct, but I am stuck. ...
10
by: Debajit Adhikary | last post by:
I have two lists: a = b = What I'd like to do is append all of the elements of b at the end of a, so that a looks like: a =
1
by: ramya naidu | last post by:
Hai iam working on a project where i use generic list to add the items and when diaplaying the items i can dispaly first and last item of the list using first and last buttons but when i press next...
2
by: =?Utf-8?B?RHJEQkY=?= | last post by:
I understand that the Value put into a DataGridViewComboBoxCell has to be a member of the Items list or an exception is thrown. I also understand that you can override that exception by handling...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.