[Tutor] split on tab and new line

kumar s ps_python at yahoo.com
Fri Sep 3 20:10:20 CEST 2004

Dear group,

I have a file1:

A 12 13 [please read one space is one tab here]
B 24 90
C 34 45

File 2:

A Apple
B Boy

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

Desired output:

Apple 12 13
Boy 24 90

My plan:
>f1 = open('file1.txt','r')
>f2 = open('file2.txt','r')

>x = f1.read()
>y = f2.read()

>list1 = split(x,'\t','\n')

here I want to split f1 on both tab and new line just
to get only column 1 of file1. In this case
list1 = ['A','B','C'] 

Similar operation for list2.

Now I have list1 and list2.
>for i in list1:
      for s in list2:
          if i == s:
            m = m.append(i)
             print "i did not find i"

My question:
1. Is it possinble to split a file on both tab and new
line. This is to get only column 1 of any matrix. If
there is some better method please suggest

2. Is my process good. I dont know myself. 

3. How can I append the values of A in file 1 to names
(column 2 of file 2).

Apple 12 13 ( how can I make Apple print next to

Please help. 

Thank you. 


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the Tutor mailing list