San k
San k

Reputation: 141

How to write multiple lines in a single line?

How can I write multiple lines in a single line? My inputs are like this:

HOXC11
HOXC11, HOX3H, MGC4906
human, Homo sapiens


HOXB6
HOXB6, HOX2, HU-2, HOX2B, Hox-2.2
human, Homo sapiens


HOXB13
HOXB13
human, Homo sapiens


PAX5
PAX5, BSAP
human, Homo sapiens

I need to make it into a single line like this:

HOXC11   HOXC11, HOX3H, MGC4906  human, Homo sapiens
HOXB6    HOXB6, HOX2, HU-2, HOX2B, Hox-2.2    human, Homo sapiens
HOXB13   HOXB13     human, Homo sapiens

Upvotes: 1

Views: 246

Answers (2)

oxymor0n
oxymor0n

Reputation: 1097

Assuming your input is from a file, let's call it homosapiens.txt, you can go from the specified input to the desired output as follow:

with open('homosapiens.txt', 'r') as f:
    for line in f:
        if line == 'human, Homo sapiens':
            print line  # this will print and go to a newline
        elif line:
            print line,  # the comma after line suppresses the newline

Upvotes: 1

pSaadi
pSaadi

Reputation: 300

  textInput = textInput.rstrip('\n')

Upvotes: 0

Related Questions