[Tutor] accessing data in a usable format
John Fouhy
john at fouhy.net
Thu Oct 18 23:11:07 CEST 2007
On 19/10/2007, Bryan Fodness <bryan.fodness at gmail.com> wrote:
> for line in file('findvalue.dat'):
> print[float(x) for x in line.split()]
>
> which returns:
>
> [1.0, 0.80000000000000004, 0.91000000000000003, 0.879]
> [2.0, 0.86199999999999999, 0.93000000000000005, 0.92700000000000005]
> [3.0, 0.90100000000000002, 0.94499999999999995, 0.95299999999999996]
> [4.0, 0.92700000000000005 , 0.95399999999999996, 0.97199999999999998]
> [5.0, 0.94199999999999995, 0.96399999999999997, 0.97699999999999998]
>
> how can I access the second and third part of the list beginning with 3.0
I would suggest building a dictionary. You want to have a dictionary
that looks like this:
findvalueDict =
{ 1.0: (0.80000000000000004, 0.91000000000000003, 0.879),
2.0: (0.86199999999999999, 0.93000000000000005, 0.92700000000000005),
# etc
}
Then you can access data by doing things like findvalueDict[3.0][1]
(will return 0.94499999999999995).
Can you see how to do that?
PS. Please use "reply to all" when you reply.
--
John.
More information about the Tutor
mailing list