Please Login in order to post a comment
Going through Text Wrap lib, it's preety easy problem need one line of command to add,
Find it below Cheers!!!!
import textwrap
def wrap(string, max_width): return textwrap.fill(string, max_width)
if name == 'main': string, max_width = input(), int(input()) result = wrap(string, max_width) print(result)
cool
def wrap(string, max_width): result= [string[i:max_width + i] for i in range(0, len(string), max_width)] return '\n'.join(result)
Easy Solution
result = "" for i in range(0, len(string), max_width): result += string[ i : i + max_width] + "\n" return result.strip()
def wrap(string, max_width): return textwrap.fill(string,max_width)
this is enought for all the test cases
without textwrap:- def wrap(string, max_width):
inilen = 0 for i in range(len(string)): print(string[i],end ='') inilen+=1 if inilen == max_width: inilen = 0 print('\n',end='') return ''
if name == 'main':
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Going through Text Wrap lib, it's preety easy problem need one line of command to add,
Find it below Cheers!!!!
import textwrap
def wrap(string, max_width): return textwrap.fill(string, max_width)
if name == 'main': string, max_width = input(), int(input()) result = wrap(string, max_width) print(result)
cool
def wrap(string, max_width): result= [string[i:max_width + i] for i in range(0, len(string), max_width)] return '\n'.join(result)
Easy Solution
result = "" for i in range(0, len(string), max_width): result += string[ i : i + max_width] + "\n" return result.strip()
def wrap(string, max_width): return textwrap.fill(string,max_width)
this is enought for all the test cases
without textwrap:- def wrap(string, max_width):
if name == 'main':