how two join and arrange two files together
Peter Otten
__peter__ at web.de
Sun Jul 19 03:21:15 EDT 2009
amrita at iisermohali.ac.in wrote:
[please keep the correspondence on the mailing list/newsgroup]
> It is working sir, but my datas are on file when i replaced StringIO("")
> with open("filename.txt") then it is not printing the result properly,
> like in one file i have data like:---
> 33 ALA H = 7.57 N = 121.52 CA = 55.58 HA = 3.89 C = 179.24
> 38 ALA H = 8.29 N = 120.62 CA = 54.33 HA = 4.04 C = 178.95
> 8 ALA H = 7.85 N = 123.95 CA = 54.67 HA = 2.98 C = 179.39
> 15 ALA H = 8.05 N = 119.31 CA = 52.18 HA = 4.52 C = 177.18
> 21 ALA H = 7.66 N = 123.58 CA = 54.33 HA = 4.05 C = 179.35
> 23 ALA H = 8.78 N = 120.16 CA = 55.84 HA = 4.14 C = 179.93
> in other:---
> 8 ALA helix (helix_alpha, helix1)
> 21 ALA helix (helix_alpha, helix2)
> 23 ALA helix (helix_alpha, helix2)
> 33 ALA helix (helix_alpha, helix3)
> 38 ALA helix (helix_alpha, helix3)
> 49 ALA bend
> and it is giving the result:-
> 15 ALA H = 8.05 N = 119.31 CA = 52.18 HA = 4.52 C = 177.18|
> 23 ALA H = 8.78 N = 120.16 CA = 55.84 HA = 4.14 C = 179.93|23 ALA helix
> (helix_alpha, helix2)
> 38 ALA H = 8.29 N = 120.62 CA = 54.33 HA = 4.04 C = 178.95|38 ALA helix
> (helix_alpha, helix3)
> |49 ALA bend
> 8 ALA H = 7.85 N = 123.95 CA = 54.67 HA = 2.98 C = 179.39|8 ALA helix
> (helix_alpha, helix1)
> it is not printing the result for 33 and 21.
Hint: you have to adapt the key() function from
def key(line):
return line[:1]
to something that returns the same key for lines in the two files that
belong together, and different keys for lines that don't.
Peter
More information about the Python-list
mailing list