def _trim_zeros_complex ( str_complexes , na_rep = 'NaN' ) : def separate_and_trim ( str_complex , na_rep ) : num_arr = str_complex . split ( '+' ) return ( _trim_zeros_float ( [ num_arr [ 0 ] ] , na_rep ) + [ '+' ] + _trim_zeros_float ( [ num_arr [ 1 ] [ : - 1 ] ] , na_rep ) + [ 'j' ] ) return [ '' . join ( separate_and_trim ( x , na_rep ) ) for x in str_complexes ]
python discard imaginary complex int
Separates the real and imaginary parts from the complex number and executes the _trim_zeros_float method on each of those .
def _trim_zeros_complex(str_complexes, na_rep='NaN'):
    """
    Separates the real and imaginary parts from the complex number, and
    executes the _trim_zeros_float method on each of those.
    """
    def separate_and_trim(str_complex, na_rep):
        num_arr = str_complex.split('+')
        return (_trim_zeros_float([num_arr[0]], na_rep) +
                ['+'] +
                _trim_zeros_float([num_arr[1][:-1]], na_rep) +
                ['j'])

    return [''.join(separate_and_trim(x, na_rep)) for x in str_complexes]