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 8656627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:19:27+00:00 2026-06-12T15:19:27+00:00

I need to combine values in second column of a tab delimited file based

  • 0

I need to combine values in second column of a tab delimited file based on the ids in first column. The example is given below. What is the fastest way to do this. I can do it using for loop, going through each line, but I am sure there is some smart way to do it, which I am not aware of.

596230  Other postop infection
596230  Disseminated candidiasis
596230  Int inf clstrdium dfcile
596230  Pressure ulcer, site NOS
2846079 Schizophrenia NOS-unspec
7800713 CHF NOS
7800713 Chr airway obstruct NEC
7800713 Polymyalgia rheumatica
7800713 DMII wo cmp nt st uncntr

into

596230  Other postop infection, Disseminated candidiasis, Int inf clstrdium dfcile, Pressure ulcer, site NOS
2846079 Schizophrenia NOS-unspec
7800713 CHF NOS, Chr airway obstruct NEC, Polymyalgia rheumatica, DMII wo cmp nt st uncntr
  • 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-06-12T15:19:28+00:00Added an answer on June 12, 2026 at 3:19 pm

    Assuming you have your text in a file:

    from collections import defaultdict
    items = defaultdict(list)
    with open("myfile.txt") as infile:
        for line in file:
            id, text = line.rstrip().split("\t")
            items[id].append(text)
    for id in items:
        print id + "\t" + ", ".join(items[id])
    

    This does not keep the original order of your ids, but it does keep the order of the texts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to combine to a string column and the result of a row_number()
Using C++ I need to combine two distinct IDs into one 16bit integer. Then
I need to combine two 32-bit values to create a 64-bit value. I'm looking
How can I combine multiple NSArrays into one array with alternating values? For example.
I have 2 lists and I need to combine the joining values from A
I need to combine two signed 8 Bit _int8 values to a signed short
I have two lists that i need to combine where the second list has
I have two arrays I want to combine. I need to take the values
I need to pull values in similar tables from two different databases, combine them
I need to combine two color values from two WriteableBitmap objects and compute something

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.