diff options
Diffstat (limited to 'challenge-002/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-002/lubos-kolouch/python/ch-1.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-002/lubos-kolouch/python/ch-1.py b/challenge-002/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..3e431db4ad --- /dev/null +++ b/challenge-002/lubos-kolouch/python/ch-1.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +""" +remove_leading_zeros - removes leading zeros from positive numbers +""" + +import re +import unittest + + +def remove_leading_zeros(num: str) -> str: + """ + Removes leading zeros from the positive number in `num` and returns the result. + + Args: + num: A string containing a positive number with leading zeros. + + Returns: + A string with the number in `num` with leading zeros removed. + """ + return re.sub(r'^0+(?!$)', '', num) + + +class TestRemoveLeadingZeros(unittest.TestCase): + + def test_remove_leading_zeros(self): + self.assertEqual(remove_leading_zeros("0001234"), "1234") + self.assertEqual(remove_leading_zeros("000"), "0") + self.assertEqual(remove_leading_zeros("0"), "0") + + +if __name__ == '__main__': + unittest.main() |
