Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Wrap code is wrong #13

Open
GunsRuth opened this issue May 18, 2021 · 1 comment
Open

Text Wrap code is wrong #13

GunsRuth opened this issue May 18, 2021 · 1 comment

Comments

@GunsRuth
Copy link

def wrap(string, max_width):
    l = []
    i = 0
    while True:
        if (i+max_width-1)<len(string)-1:
            l.append(string[i:i+max_width])
            i = i+max_width
        else:
            l.append(string[i:])
            break
    return '\n'.join(l)

Better answer

@LeoDuran01
Copy link

using the textwrap library you have better code:

import textwrap as tr

def wrap(string, max_width):
l = tr.wrap(string, width=max_width)
return '\n'.join(l)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants