Il giorno 05/dic/2013, alle ore 11:55, Alberto Granzotto <agran...@gmail.com> ha scritto:
> > On Thu, Dec 5, 2013 at 12:54 AM, Dario Bertini <berda...@gmail.com> wrote: > >>> def height(tree): > ... if len(tree) == 0: > ... return 1 > ... else: > ... return 1+max(map(height, tree)) > > > bello, molto elegante l'uso di map con la funzione ricorsiva. Stesso algoritmo, con sintassi un po’ più compatta: def depth(tree): return 1 if not tree else 1+max(map(depth, tree)) con le list comprehension: def depth(tree): return 1 if not tree else 1+max([depth(t) for t in tree]) con le generator expressions (quasi uguale): def depth(tree): return 1 if not tree else 1+max((depth(t) for t in tree)) — Federico _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python