Hi, On 17th Dec. I posted one question, how to arrange datafile in a particular fashion so that I can have only residue no. and chemical shift value of the atom as: 1 H=nil 2 H=8.8500 3 H=8.7530 4 H=7.9100 5 H=7.4450 ........ Peter has replied to this mail but since I haven't subscribe to the tutor mailing list earlier hence I didn't receive the reply, I apologize for my mistake, today I checked his reply and he asked me to do few things:
Can you read a file line by line? Can you split the line into a list of strings at whitespace occurences? Can you extract the first item from the list and convert it to an int? Can you remove the first two items from the list? Can you split the items in the list at the "="? I tried these and here is the code: f=open('filename') lines=f.readlines() new=lines.split() 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? 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}, 3: {'H': 8.753, 'HA': 4.034, 'HB2': 1.808, 'N': 123.238}, 4: {'H': 7.91, 'HA': 3.862, 'HB2': 1.744, 'HG2': 1.441, 'N': 117.981}, 5: {'H': 7.445, 'HA': 4.077, 'HB2': 1.765, 'HG2': 1.413, 'N': 115.479}, 6: {'H': 7.687, 'HA': 4.21, 'HB2': 1.386, 'HB3': 1.605, 'HD11': 0.769, 'HD12': 0.769, 'HD13': 0.769, 'HG': 1.513, 'N': 117.326}, 7: {'H': 7.819, 'HA': 4.554, 'HB2': 3.136, 'N': 117.08}, 8: {'HD2': 3.745}, 9: {'H': 8.235, 'HA': 4.012, 'HB2': 2.137, 'N': 116.366}, 10: {'H': 7.979, 'HA': 3.697, 'HB': 1.88, 'HG12': 1.601, 'HG13': 2.167, 'HG21': 0.847, 'HG22': 0.847, 'HG23': 0.847, 'N': 119.03}, 11: {'H': 7.947, 'HA': 4.369, 'HB3': 2.514, 'N': 117.862}, 12: {'H': 8.191, 'HA': 4.192, 'HB2': 3.156, 'N': 121.264}, 13: {'H': 8.133, 'HA': 3.817, 'HB3': 1.788, 'HD11': 0.862, 'HD12': 0.862, 'HD13': 0.862, 'HG': 1.581, 'N': 119.136}} If not then please help to point out my mistake so that I can get the correct output. Thanking you for your help and time. Thanks, Amrita _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor