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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Python
  3. Strings
  4. Text Wrap
  5. Discussions

Text Wrap

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 1640 Discussions, By:

recency

Please Login in order to post a comment

  • sallulearnscode
    3 days ago+ 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|
    Permalink
  • g_hiwetmit
    3 days ago+ 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|
    Permalink
  • mister_harshkum1
    6 days ago+ 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|
    Permalink
  • verdox162
    1 week ago+ 0 comments
    def wrap(string, max_width):
        return '\n'.join(textwrap.wrap(string,max_width))
    
    1|
    Permalink
  • jeevan_manavalan
    1 week ago+ 1 comment
    return textwrap.fill(string, max_width)
    
    3|
    Permalink
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy