Re: [Tutor] populating an array or using a dictionary

2007-10-21 Thread Kent Johnson
Michael Langford wrote: > A neater way to do it looks like: > > dic2 = {} > countOfVars=40 > for line in file('foo.dat'): > tokens = line.split() > dval = tokens[0] > ls = [] > for i in range(1,countOfVars+1): > ls.append(float(tokens[i])) > dic2[dval]=tuple(ls) > p

Re: [Tutor] populating an array or using a dictionary

2007-10-21 Thread Kent Johnson
Bryan Fodness wrote: > it doesn't fix the problem, now it says there is a syntax error on the > equal sign. Please, post your code and the exact error message and traceback! Don't make us guess what you are doing! My guess is you forgot the closing ) but I have no way to know for sure. Kent >

Re: [Tutor] populating an array or using a dictionary

2007-10-21 Thread Michael Langford
Using the attached foo.dat and no linebreaks, what you're doing works perfectly: dic2 = {} for line in file('foo.dat'): d, fs1, fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9, fs10, fs11, fs12, fs13, fs14, fs15, fs16, fs17, fs18, fs19, fs20, fs21, fs22, fs23, fs24, fs25, fs26, fs27, fs28, fs29, fs30, f

Re: [Tutor] populating an array or using a dictionary

2007-10-21 Thread Bryan Fodness
it works well if it is on the same line, but I would like to wrap it for readability On 10/21/07, Bryan Fodness <[EMAIL PROTECTED]> wrote: > > it doesn't fix the problem, now it says there is a syntax error on the > equal sign. > > On 10/21/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > > > > > > "Br

Re: [Tutor] populating an array or using a dictionary

2007-10-21 Thread Bryan Fodness
it doesn't fix the problem, now it says there is a syntax error on the equal sign. On 10/21/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > > > "Bryan Fodness" <[EMAIL PROTECTED]> wrote in > > >d, fs1, fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9, fs10, > >fs11, fs12, fs13, fs14, fs15, fs16, fs17, f

Re: [Tutor] populating an array or using a dictionary

2007-10-21 Thread Alan Gauld
"Bryan Fodness" <[EMAIL PROTECTED]> wrote in >d, fs1, fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9, fs10, >fs11, fs12, fs13, fs14, fs15, fs16, fs17, fs18, fs19, >fs20, fs21, fs22, fs23, fs24, fs25, fs26, fs27, fs28, >fs29, fs30, fs31, fs32, fs33, fs34, fs35, fs36, fs37, >fs38, fs39

Re: [Tutor] populating an array or using a dictionary

2007-10-21 Thread Bryan Fodness
Here is my code. dic2 = {} for line in file('21Ex6MV_tmr.dat'): d, fs1, fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9, fs10, fs11, fs12, fs13, fs14, fs15, fs16, fs17, fs18, fs19, fs20, fs21, fs22, fs23, fs24, fs25, fs26, fs27, fs28, fs29, fs30, fs31, fs32, fs33, fs34, fs35, fs36, fs37,

Re: [Tutor] populating an array or using a dictionary

2007-10-21 Thread Aditya Lal
If the ease of use is the only answer then the size of the file should not matter ideally. btw, how large is the file ? is it in MBs or GBs ? For performance reasons, typically you should not have any problems using either dictionary, array or list for file size of few KBs. Like Kent said, if you

Re: [Tutor] populating an array or using a dictionary

2007-10-19 Thread Eric Brunson
Bryan Fodness wrote: > The data file is larger than shown, and I was wondering if it would be > better to populate an array or create a dictionary. Which would be > easier? > A dictionary is an array with an index, if you need an index into your data, use a dictionary, if not use an array. >

Re: [Tutor] populating an array or using a dictionary

2007-10-19 Thread Bryan Fodness
The data file is larger than shown, and I was wondering if it would be better to populate an array or create a dictionary. Which would be easier? On 10/19/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > > Bryan Fodness wrote: > > I have a data file that I would like to extract data from: > > > > F

Re: [Tutor] populating an array or using a dictionary

2007-10-19 Thread Kent Johnson
Bryan Fodness wrote: > I have a data file that I would like to extract data from: > > FS 1 2 3 4 5 > 1.5 1.000 1.000 1.000 1.000 1.000 > 2.0 0.985 0.994 0.997 0.996 0.996 > 2.5 0.967 0.976 0.981 0.981 0.982 > 3.0 0.949 0.958 0.965 0.966 0.967 > 3.

[Tutor] populating an array or using a dictionary

2007-10-19 Thread Bryan Fodness
I have a data file that I would like to extract data from: FS 1 2 3 4 5 1.5 1.000 1.000 1.000 1.000 1.000 2.0 0.985 0.994 0.997 0.996 0.996 2.5 0.967 0.976 0.981 0.981 0.982 3.0 0.949 0.958 0.965 0.966 0.967 3.5 0.925 0.937 0.945 0.948 0.