We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
+ 0 comments The Most Precise and Most Efficient Code for this problem.
def wrap(string, max_width): return textwrap.TextWrapper(max_width).fill(string)
+ 0 comments def wrap(string, max_width): result = '' _start = int(0) _end = int(max_width) while _end < len(string): substring = string[_start: _end] result = result + substring + '\n' _start = _end _end = _end + max_width result = result + string[_start:] return result
+ 0 comments import textwrap import math
def wrap(string, max_width): s = '' j = 0 lines = len(string)/max_width lu = math.ceil(lines) # print(lu) for i in range(math.ceil(lines)):
s +='{}\n'.format( string[j: j+ max_width]) j += max_width # print(textwrap.fill(l,7)) return (s)
+ 0 comments def wrap(string, max_width): return '\n'.join(textwrap.wrap(string,max_width))
+ 1 comment return textwrap.fill(string, max_width)
Load more conversations
Sort 1640 Discussions, By:
Please Login in order to post a comment