Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 896001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:39:17+00:00 2026-05-15T14:39:17+00:00

I have a tab-delimited file as below: A 3 A 6 B 6 B

  • 0

I have a tab-delimited file as below:

A    3    A    6
B    6    B    9
C    0    C    2

I wish to read the file in as below:

LIST = [['A', '3'], ['B', '6'], ['C', '0'], ['A', '6'], ['B', '9'], ['C', '2']]

The order is not important. I am only concerned that each row is read in increments of two and assigned to a sub list.

Any suggestions?

Thanks,
S 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:39:17+00:00Added an answer on May 15, 2026 at 2:39 pm

    The most straightforward way would be:

    >>> n = []
    >>> for line in open(fname):
        els = line.split('\t')
        n.append(els[:2])
        n.append(els[2:])
    
    
    >>> n
    [['A', '3'], ['A', '6'], ['B', '6'], ['B', '9'], ['C', '0'], ['C', '2']]
    

    maybe slightly more efficient would be:

    >>> g = (line.split('\t') for line in open(fname))
    >>> [els[i:i+2] for els in g for i in range(0, 4, 2)]
    [['A', '3'], ['A', '6'], ['B', '6'], ['B', '9'], ['C', '0'], ['C', '2']]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read in a text file that is tab delimited, i then have a
I have a 600MB tab delimited file that needs to be sorted using only
I have a tab delimited file on a shared path. I've setup that flat
I have a tab-delimited file that has over 200 million lines. What's the fastest
I have a text file that is tab delimited and looks like: 1_0 NP_045689
So I have a tab delimited file that I need to insert through sqlbulkinsert.
Almost every project that I work will have some sort of tab delimited file
I have a tab delimited file that contains date, header row, some values, empty
I have a tab-delimited text file that I am parsing. Its first column contains
Basically I have converted a tab delimited txt file into a list containing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.