GH avatar Bite 53. Convert text into multiple columns

You run a news site and you got feedback that people read more if articles are printed in 2 or more columns instead of long walls of text.

Oh no! There are 200 articles in the database that need to be reformatted!

The good news though is that you know Python so you decide to come up with a nice function to do this tedious work for you.

And that's where our Bite comes in: complete text_to_columns which takes a text and splits it into columns (COL_WIDTH is set to 20).

The amount of double newlines (\n\n) in the text decides how many columns there will be so we can assume you are delivered the text in this preformatted way.

It's best to show you some examples how this would work, see the examples here (these are also used in the TESTS tab).

Get to know the the standard library ... we reckon you probably want to leverage at least 2 modules for this. As this is an Advanced Bite we leave it at that. Good luck and have fun!

go back Advanced level
Bitecoin 4X

56 out of 59 users completed this Bite.
Will you be Pythonista #57 to crack this Bite?
Resolution time: ~88 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 5.75 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Buy Now Login and get coding
We use Python 3.7