We use Python 3.6

go back Level: Advanced (img: AV / score: 4) level Bite 53. Convert text into multiple columns

12 out of 12 users completed this Bite ...
Will you be Pythonista #13 to crack this Bite?
Average Bite difficulty 1-10 rating: 4.0
» Up for a challenge? 💪

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!

Github login button