Python Questions - Need Solutions in Python

Q1. We are building a word processor and we would like to implement a "word-wrap" functionality.

Given a list of words followed by a maximum number of characters in a line, return a collection of strings where each string element represents a line that contains as many words as possible, with the words in each line being concatenated with a single '-' (representing a space, but easier to see for testing). The length of each string must not exceed the maximum character length per line.

Your function should take in the maximum characters per line and return a data structure representing all lines in the indicated max length.


words1 = [ "The", "day", "began", "as", "still", "as", "the",

"night", "abruptly", "lighted", "with", "brilliant",

"flame" ]

wrapLines(words1, 13) "wrap words1 to line length 13" =>

[ "The-day-began",






"flame" ]

wrapLines(words1, 20) "wrap words1 to line length 20" =>

[ "The-day-began-as",



"with-brilliant-flame" ]

words2 = [ "Hello" ]

wrapLines(words2, 5) "wrap words2 to line length 5" =>

[ "Hello" ]

words3 = [ "Hello", "world" ]

wrapLines(words3, 5) "wrap words3 to line length 5" =>

[ "Hello",

"world" ]

words4 = ["Well", "Hello", "world" ]

wrapLines(words4, 5) "wrap words4 to line length 5" =>

[ "Well",


"world" ]

words5 = ["Hello", "HelloWorld", "Hello", "Hello"]

wrapLines(words5, 20) "wrap words 5 to line length 20 =>

[ "Hello-HelloWorld",

"Hello-Hello" ]

All Test Cases:

words, max line length

wrapLines(words1, 13)

wrapLines(words1, 20)

wrapLines(words2, 5)

wrapLines(words3, 5)

wrapLines(words4, 5)

wrapLines(words5, 20)

n = number of words OR total characters

Q2. We are building a word processor and we would like to implement a "reflow" functionality that also applies full justification to the text.

Given an array containing lines of text and a new maximum width, re-flow the text to fit the new width. Each line should have the exact specified width. If any line is too short, insert '-' (as stand-ins for spaces) between words as equally as possible until it fits.

Note: we are using '-' instead of spaces between words to make testing and visual verification of the results easier.

lines = [ "The day began as still as the",

"night abruptly lighted with",

"brilliant flame" ]

reflowAndJustify(lines, 24) "reflow lines and justify to length 24" =>

[ "The--day--began-as-still",



"flame" ] // <--- a single word on a line is not padded with spaces

reflowAndJustify(lines, 25) "reflow lines and justify to length 25" =>

[ "The-day-began-as-still-as"



"flame" ]

reflowAndJustify(lines, 26) "reflow lines and justify to length 26" =>

[ "The--day-began-as-still-as",


"with----brilliant----flame" ]

reflowAndJustify(lines, 40) "reflow lines and justify to length 40" =>

[ "The--day--began--as--still--as-the-night",

"abruptly--lighted--with--brilliant-flame" ]

reflowAndJustify(lines, 14) "reflow lines and justify to length 14" =>








All Test Cases:

lines, reflow width

reflowAndJustify(lines, 24)

reflowAndJustify(lines, 25)

reflowAndJustify(lines, 26)

reflowAndJustify(lines, 40)

reflowAndJustify(lines, 14)

n = number of words OR total characters

Kemahiran: Python, Computer Science

Tentang Klien:
( 1 ulasan ) DEWAS, India

ID Projek: #34321224

Dianugerahkan kepada:


Hi there! I am Professional in Scraping Data , Data Entry Operator and Python expert in since 2 years.I have gone through your outsourced requirement and have analyzed that I have right credentials To do this job prop Lagi

₹1200 INR dalam 7 hari
(3 Ulasan)

Hi, I hope you are doing great. I saw your two questions. I can help with implement both of these as I have multiple years of experience with python programming and I can start immediately if you want to and can delive Lagi

₹1000 INR dalam sehari
(5 Ulasan)

7 pekerja bebas membida secara purata ₹2021 untuk pekerjaan ini


I am Ring. I am about 19+ years experienced in GNU/Linux based system, server installation and customization, develop, deploy, security and support. I may help you in this regard.

₹3500 INR dalam sehari
(11 Ulasan)

Hello I have read the questions and i can provide the solutions for you with details comments explaining each part of the code

₹5000 INR dalam 7 hari
(19 Ulasan)

Hi, there. Python is my first skill and the Answer is wonderful. I would love to discuss your problem with [login to view URL]

₹1500 INR dalam 7 hari
(3 Ulasan)

I'll do your task within a few hours without any mistakes and problems. The bid amount and some questions may be discussed in a private chat.

₹900 INR dalam sehari
(0 Ulasan)

Hi there! I just checked the two questions and I'll be glad to provide you with a detailed solution. I am a software engineer with 5+ years of experience in python and solving problems in this language became pretty in Lagi

₹1050 INR dalam 7 hari
(0 Ulasan)