Skip to main content
1 of 2
wjandrea
  • 720
  • 9
  • 22

Python 3

s = input()
x = len(s) // 2
# Print "s" up to "x", then "s" past "x", joined on newlines.
print(s[:x], s[x:], sep="\n")

For example,

$ echo abcdef | python3 -c 's = input(); x = len(s) // 2; print(s[:x], s[x:], sep="\n")'
abc
def

If the string length is not an even number, the second line will be longer. E.g.

$ echo abcdefg | python3 -c 's = input(); x= len(s) // 2; print(s[:x], s[x:], sep="\n")'
abc
defg
wjandrea
  • 720
  • 9
  • 22