This question is concerning the flatten, size and transform functions for list structures, defined in home assignment #5 question #2.
All three functions are recursive, yet the first two functions (flatten, size) use slicing of the original list (list + list[1:]),
while the third (transorm) requires iterating over all the list elements using a "for" loop.
Once the assignment was published, I succeeded in writing the solution myself, but suddenly I can't understand the difference between the functions, causing the different implementations.
Why does "Transform" cannot be implemented using slicing? (I tried it, it cause much balagan).
I attach my code, for convenience.
def flatten(lst): final =  if type(lst)==int: return final+[lst] elif lst==: return final else: cnt=0 while cnt<len(lst): final = final+flatten(lst[cnt]) cnt+=1 return final def size(lst): final=0 if type(lst)==int: return 1 if lst==: return 1 else: final += 1 for elem in lst: final += size(elem) return final def transform(f, lst): final =  if type(lst)==int: return f(lst) elif lst==: return  else: for elem in lst: final.append(transform(f, elem)) return final
I would appreciate any help.
Good luck to all!