Search code examples
pythonstringshort

How to change a vertical string to a horizontal string in python?


I have tried using those script but they don't work. (x is a vertical variable)

print "".join(x.split())

and

x.replace("\n", "")

(try to explain your answer if you can) SAMPLE INPUT-OUTPUT: Input:

  • H
  • E
  • L
  • L
  • O

Output: HELLO ABC


Solution

  • input=(a\nb\nc\nd\nA\nB\nC\n) #<---Vertical text
    
    result=input.replace("\n", "") #Convert the vertical text to horizontal text
    
    print(result) #Print the horizontal text
    

    Output: abcABC

    100% working for my program