[Tutor] arrangement of datafile
Dave Angel
davea at davea.name
Wed Dec 25 12:28:52 CET 2013
On Wed, 25 Dec 2013 16:17:27 +0800, Amrita Kumari
<amrita.g13 at gmail.com> wrote:
> I tried these and here is the code:
> f=open('filename')
> lines=f.readlines()
> new=lines.split()
That line will throw an exception.
> number=int(new[0])
> mylist=[i.split('=')[0] for i in new]
> one thing I don't understand is why you asked to remove first two
> items from the list?
You don't show us the data file, but presumably he would ask that
because the first two lines held different formats of data. Like your
number= line was intended to fetch a count from only line zero?
> and is the above code alright?, it can produce
> output like the one you mentioned:
> {1: {'HA2': 3.785, 'HA3': 3.913},
> 2: {'H': 8.85, 'HA': 4.337, 'N': 115.757},
The code above won't produce a dict of dicts. It won't even get past
the exception. Please use copy/paste.
--
DaveA
More information about the Tutor
mailing list