Home > Problem, Projects/Experiments, Python > Python Project: Split and join

Python Project: Split and join




Python: Split and join


Split up the message on newline

The target of this task is to Split a given text message on the newline (\n) then use the join builtin to stitch it together using a ‘|’ (pipe).

I fond this on the pybites web-site as a code-challenges bites #104. In our case we will print the new Message within the function but we can return it back as a variable for more usage in our code..

Enhancements: If we want to do some enhancements to this code:

1. We can read the message from a file.

2. Letting the user to select the joining character.

3. Also we may export the final message to another txt file.


We assume our message is “Hello world!\nWe hope that you are learning a lot of Python.\nHave fun with our Bites of Py.\nKeep calm and code in Python!\nBecome a PyBites ninja!”



The Code:


def split_in_columns(message=message):

sp_message = message.split(“\n”)

message=”|”.join(sp_message)

print(message)

split_in_columns(message=message)







Follow me on Twitter..

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s