[Tutor] split on tab and new line

Alan Gauld alan.gauld at blueyonder.co.uk
Fri Sep 3 22:41:47 CEST 2004


> I have a file1:
> 
> A 12 13 [please read one space is one tab here]

> File 2:
> 
> A Apple
> 
> Now I want to check if A in file2 is existing in
> File1, if then, I want to print corresponding element
> of A in File2, Apple and corresponding value of A in
> File1.
> 
> Desired output:
> 
> Apple 12 13

I'd suggest using a pair of dictionaries loaded from the files 
(Might be a problem is very big files (>1MB)...).
Then you can go:

for key in File2.keys():
    try: print File2[key], file1[key]
    except KeyError: continue

HTH,

Alan G.


More information about the Tutor mailing list