【发布时间】:2018-07-12 13:03:10
【问题描述】:
我有以下代码,它运行良好并给了我预期的结果,但我知道有一种方法可以简化它,我不知道最好的方法是让以下代码改为 3/4 行20个左右。 Python 专家需要您的建议,我如何简化以下代码。
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
【问题讨论】:
-
如果您解释一下代码的作用会有所帮助。
-
我投票决定将此问题作为题外话结束,因为它应该发布在codereview.stackexchange.com
-
实际输入和预期输出是多少?考虑另一种方法可能比尝试修复这个方法更容易。
-
如果您的代码正常工作,这个问题可能更适合codereview.stackexchange.com
-
哦,谢谢,我不知道 codereview 的事情。将删除此问题并将其发布在此处
标签: python if-statement simplify