sumcalc()
doesn't do anything on its own; you need to use the return value. Beyond this, the index checking is unecessary, as the return
could simply be placed after the loop. Here is a simpler way of writing the nested sum code.
def nested_sum(x):
if type(x)==int:
return x
if type(x)==list:
return sum(
nested_sum(item)
for item in x
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…