educative.io

Educative

More Pythonic way

def inorder_iterative(node):
  result = ''
  stack = []
  while node or stack:
    if node:
      stack.append(node)
      node = node.left
    else:
      node = stack.pop()
      result += str(node.data) + ' '
      node = node.right

  return result
1 Like

Hi @Vladimir_Ryabtsev,

Thank you so much for reaching out to us.

I really like your solution both of the solutions (this and in the course) give the same output and we also use the list in both of them but again, I like this one :slight_smile: .

If you have any other query then please do reach out to us. Thank you.