Suoritettu

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.

Examples:

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",

"as-still-as",

"the-night",

"abruptly",

"lighted-with",

"brilliant",

"flame" ]

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

[ "The-day-began-as",

"still-as-the-night",

"abruptly-lighted",

"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",

"Hello",

"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",

"as--the--night--abruptly",

"lighted--with--brilliant",

"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"

"the-----night----abruptly"

"lighted---with--brilliant"

"flame" ]

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

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

"the-night-abruptly-lighted",

"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" =>

['The--day-began',

'as---still--as',

'the------night',

'abruptly',

'lighted---with',

'brilliant',

'flame']

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

Taidot: Python, Computer Science

Tietoa asiakkaasta:
( 1 arvostelu ) DEWAS, India

Projektin tunnus: #34321224

Myönnetty käyttäjälle:

AmineDN

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 Lisää

₹1200 INR 7 päivässä
(3 Arvostelua)
2.7
taimourhadi

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 Lisää

₹1000 INR 1 päivässä
(5 Arvostelua)
3.8

7 freelanceria on tarjonnut keskimäärin ₹2021 tähän työhön

toshazed

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 1 päivässä
(11 arvostelua)
3.9
Demaxl

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 7 päivässä
(19 arvostelua)
3.8
Divyasree10

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 7 päivässä
(3 arvostelua)
2.3
RRedBaron

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 1 päivässä
(0 arvostelua)
0.0
eeykram

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 Lisää

₹1050 INR 7 päivässä
(0 arvostelua)
0.0