I am new to C and trying to learn by comparison with Python.
My question is trivial, but I still need some explanations from experts. Here is a Python nested list structure:
L = [1, [2, [3, 4], 5], 6, [7, 8]]
And here is an interesting piece of code (taken from 'Learning Python' by Lutz) to handle nested structures (sum elements):
def sumtree(L):
tot = 0
for x in L:
if not isinstance(x, list):
tot += x
else:
tot += sumtree(x)
return tot
If I pass L into this function I will get 36, which is a sum of elements in L. How exactly can nested lists and this particular function be translated into C?