-2

I have a tab-delimited file with three columns (Name Nr1 Nr2) like the following:

ABC 201 215

DEF 301 320

GHI 350 375

I would like to transfer the last file into the following format:

ABC 201 201 #taking the value from the first value from the second column and continue line by line till the second value in the third line as the following

ABC 202 202

ABC 203 203

......and so on till the third column value

ABC 215 215

DEF 301 301 ....and so on till the third column value

DEF 320 320

GHI 350 350

GHI 351 351

GHI 351 351

....

GHI 375 375

is that possible in python?

I would really appreciate your help in this Thanks in advance

Nawar
  • 1
  • 1

1 Answers1

0

Using the method here: How do I read a file line-by-line into a list?

You can take each line of the file and make it into an array.

lines = tuple(open(filename, 'r'))

As shown here: splitting a string based on tab in the file

You can then split each array value by the tab delimiter.

import re
line_array = re.split(r'\t+', lines[0])
Community
  • 1
  • 1
SalientGreen
  • 4,764
  • 3
  • 15
  • 20