[Tutor] iterating data and populating a dictionary
Alan Gauld
alan.gauld at btinternet.com
Tue Aug 5 18:51:02 CEST 2008
"Bryan Fodness" <bryan.fodness at gmail.com> wrote
> i am filling a dictionary with a dictionary and my values for
> isegment[field] are identical. i can't see where i am overwriting
> the
> previous field values.
Show us the full error text do not just summarize.
> i would like to have something like, {1: {'Value': 0.0, ...}, 2:
> {'Value':
Describe the output you expected and what you got (if anything)
> for line in file(data_file):
> the_line = line.split()
> if the_line:
> if the_line[0] == 'Field':
> field += 1
> elif the_line[0] == 'Index':
> index = float(the_line[-1])
> dif_index = index - start_index
> iindex[field] = dif_index
Here index is assigned to a floating point number.
Then it is indexed. Floats don't have indexes...
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list