On Jul 15, 11:13 am, amr...@iisermohali.ac.in wrote: > Dear all, > > Just one more thing i want to ask that suppose i have a file like:--- > > 47 8 ALA H H 7.85 0.02 1 > 48 8 ALA HA H 2.98 0.02 1 > 49 8 ALA HB H 1.05 0.02 1 > 50 8 ALA C C 179.39 0.3 1 > 51 8 ALA CA C 54.67 0.3 1 > 52 8 ALA CB C 18.85 0.3 1 > 53 8 ALA N N 123.95 0.3 1 > 107 15 ALA H H 8.05 0.02 1 > 108 15 ALA HA H 4.52 0.02 1 > > now what i want that i will make another file in which first it will write > the position of ALA lets say 8 then its name ALA and then the chemical > shift value for only three atoms C,CA and CB. > > Means it will be someting like: > > 8 ALA C = 179.39 CA = 54.67 CB = 18.85 > > I tried but its not coming. > > Thanks, > Amrita Kumari > Research Fellow > IISER Mohali > Chandigarh > INDIA
This is indeed possible and should be quite easy. One problem is that I do not exactly understand the problem - how do you decide which all to join and print? Is it ALA with 4th field as C or 6th field as 0.3? The issue here is that I am not getting the context of your problem. And I have *no* idea about the Chemical shift etc which you are talking about. If you can explain it a little more, I will try something out. Just for the scenario you explained, this code will suffice - f = open('abcd') d = {} for line in f: fields = line.split() if fields[2] == 'ALA': d.setdefault('ALA', {'position':fields[1], 'values':[]}) if fields[4] == 'C': d['ALA']['values'].append({fields[3]:fields[5]}) print d But i dont think this is what you want -- http://mail.python.org/mailman/listinfo/python-list