Skip to content

Instantly share code, notes, and snippets.

@mkckr0
Created February 4, 2023 15:41
Show Gist options
  • Save mkckr0/b31fefb723ba6673e8012a98170450bc to your computer and use it in GitHub Desktop.
Save mkckr0/b31fefb723ba6673e8012a98170450bc to your computer and use it in GitHub Desktop.
format all int to same width
class int_fmt:
digit_count: int
def __init__(self, max_n: int) -> None:
self.digit_count = len(str(max_n))
def __call__(self, n: int) -> str:
return '{n:0{w}d}'.format(n=n, w=self.digit_count)
fmt = int_fmt(100)
fmt(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment