0

I have a big txt file that contains data like such:

ID:000001 Status:Active
Gender:Male Profile:Adult
User_access:PUBLIC
...

and I want the output to be like:

ID:000001
Status:Active
Gender:Male
Profile:Adult
User_access:Public
...

What I've tried:

for line in input_file:
  if ' ' in line:
     print(line.replace(' ', '\n'))

This works but it's taking into account the end of line as space which is not ideal with my sort of big file:

ID:000001
Status:Active
#space
Gender:Male
Profile:Adult
#space
User_access:Public
  • "This works but it's taking into account the end of line as space " No; it's putting a newline at the end *because that's what `print` normally does*. – Karl Knechtel Sep 03 '21 at 01:59

0 Answers0