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

Code error on prettify function #7

Open
RobertTura opened this issue Oct 21, 2022 · 0 comments
Open

Code error on prettify function #7

RobertTura opened this issue Oct 21, 2022 · 0 comments

Comments

@RobertTura
Copy link

RobertTura commented Oct 21, 2022

The function prettify has a self-loop, but it doesn't account for a different character in the loop it just affects the first iteration.
This is the solution to the error.

def prettify(amount, separator=','): """Separate with predefined separator.""" orig = str(amount) new = re.sub("^(-?\d+)(\d{3})", "\g<1>{0}\g<2>".format(separator), str(amount)) if orig == new: return new else: return prettify(new, separator)

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

1 participant