def remove_leading_zeros ( num : str ) -> str : if not num : return num if num . startswith ( 'M' ) : ret = 'M' + num [ 1 : ] . lstrip ( '0' ) elif num . startswith ( '-' ) : ret = '-' + num [ 1 : ] . lstrip ( '0' ) else : ret = num . lstrip ( '0' ) return '0' if ret in ( '' , 'M' , '-' ) else ret
how to keep leading zero's in an integer in python
Strips zeros while handling - M and empty strings
def remove_leading_zeros(num: str) -> str:
    """
    Strips zeros while handling -, M, and empty strings
    """
    if not num:
        return num
    if num.startswith('M'):
        ret = 'M' + num[1:].lstrip('0')
    elif num.startswith('-'):
        ret = '-' + num[1:].lstrip('0')
    else:
        ret = num.lstrip('0')
    return '0' if ret in ('', 'M', '-') else ret