Creating dynamically named lists/dictionaries

Rogue 9 rogue9 at ntlworld.com
Wed Apr 23 19:22:18 EDT 2003


Hi all,
	I'm new to both programming and Python in particular and have run in to a
snag while trying to write my own program.I have looked through books and
the web but haven't as yet found an answer so I though I might try a post
here to see if anyone could point me in the right direction.
	Okay my program is for analysing a Lottery Draw results text file I have
pre-formatted so that each line contains 7 comma separated values (Draw
number and six values representing the numbers drawn in numerically
ascending order.
	I've sussed out how to open the file read in the lines and I have split
the strings first by the '\n' newline symbol and then I have split it
again by ','.I've also turned the values back into integers as they were
strings.Now what I've ended up with is a list containing one draw result
for each week (768 at the last count)as individual items in that list e.g
list =[[767,11,22,33,44,45,46]......[1,20,33,41,45,46,47]]
	What I really want is a list or dictionary for each individual weeks
result but I can't seem to work out how to dynamically create a list or
dict with a unique name for each week.The results file will grow and I
don't fancy creating 768+ lines of code just to instantiate a list or
dict.At first I tried looping a variable equal to the length of the file
as in:
	x=len(filelength)
	'draw'+str(x)=[drawresult]
I thought this would dynamically make a whole bunch of lists such as
draw1,draw2 etc. but all I got was errors.
	I hope I have explained my 'problem' sufficiently for someone to help or
to at least point me in the right direction to work towards a solution.
	Yours hopefully,
		Rogue9




More information about the Python-list mailing list