jeudi 12 juillet 2018

simplify if statement in python 3.6

I have the following code which is working fine and giving me the expected result, but i know there is a way to simplify it and i don't whats the best to way make to following code can be 3/4 lines instead of 20 odd or so. Python experts need your advice how i can ease the following code.

for ele in hng_row:
    if not ele.isdigit():
        if not ele.isalpha():
            if not ele.isalnum():
                if ele.endswith('.00'):
                    get_index = hng_row.index(ele)
                    ele = ele[:-1]
                    hng_row[get_index] = ele
                if ele.startswith('0.') and ele.endswith('0') and ele != '0.0':
                    get_index = hng_row.index(ele)
                    ele = ele[:-1]
                    hng_row[get_index] = ele
                if (ele[-2] != '0' ) and (ele[-2] != '.') and (ele[-1] == '0'):
                    get_index = hng_row.index(ele)
                    ele = ele[:-1]
                    hng_row[get_index] = ele

Aucun commentaire:

Enregistrer un commentaire