Function that shows list in reverse order

0
def imprimeDeTrasParaFrente(lista):
    if lista == None :
       return
    imprimeDeTrasParaFrente(lista.proximo)
    print lista,

class Node(object):

   def __init__(self, carga=None, proximo=None):
       self.carga = carga
       self.proximo = proximo

   def __str__(self):
       return str(self.carga)

   no1, no2, no3 = Node(1), Node(2), Node(3)
   no1.proximo, no2.proximo = no2, no3

   imprimeDeTrasParaFrente(no1)

With the PrintFeatureFeature () function I was able to print the elements of the list in reverse order, and it only checks if the list is empty and calls itself with the next node in the list. In my perspective the print function is never called because when the list is empty the function simply returns and terminates the program, or am I wrong?

    
asked by anonymous 24.10.2017 / 21:21

1 answer

0

There is nothing wrong with the logic of your program, it works exactly as you described it: it displays the values contained in the nodes of a threaded list by iterating from the last node to the first.

What is making it not work is the indentation of the blocks, which is crucial in Python .

For everything to work perfectly, be aware of the code indentation:

Reference Wikibooks

    
25.10.2017 / 15:26