how to adding new tab in readline python
Question: I have a problem can't adding a new tab in reading file.  
I've tried readline, but I am confused..  

    
    
    f = open('data.txt', 'r')
    count = 0
    for i in f.readlines():
         count += 1
         if count == 3:
              #adding new tab
         print i,
    

In here, I have `data.txt` which contains data like this:

    
    
    af  Afrikaans
    sq  Albanian
    ar  Arabic
    hy  Armenian
    az  Azerbaijani
    eu  Basque
    

But I can't adding new tab if the data is in a certain count readline.  
I want to make it like this..

    
    
    af  Afrikaans      hy   Armenian
    sq  Albanian       az   Azerbaijani
    ar  Arabic         eu   Basque
    


Answer: you can create one list to store your lines per 3 iteration then append this
it to `last_q` and at last you can use `zip` function to zip `last_q` and join
the pairs with `\t` then write to file again :

    
    
    import copy
    q = []
    last_q= []
    with open('newefile.txt','r') as f:
       for line in f:
            q.append(line.strip())
            if len(q)==3 :
                last_q.append(copy.copy(q))
                q=[]
    
    with open('newefile.txt','w') as f:
        for lines in zip(*last_q) :
            print lines
            f.write('\t'.join(lines)+'\n')
    

Demo :

    
    
    print last_q    
    deque([deque(['af  Afrikaans\thy  Armenian', 'sq  Albanian\taz  Azerbaijani', 'ar  Arabic\teu  Basque'], maxlen=3)]) 
    
    print zip(*last_q)
    [('af  Afrikaans', 'hy  Armenian'), ('sq  Albanian', 'az  Azerbaijani'), ('ar  Arabic', 'eu  Basque')]
    

Final result :

    
    
    af  Afrikaans   hy  Armenian
    sq  Albanian    az  Azerbaijani
    ar  Arabic      eu  Basque
    

