def pre_order_list(node, filter_func=no_filter):
 (l, stack) = ([], [])
 (poped, index) = (0, 0)
 while node:
  if filter_func(node):
   if (not poped):
    l.append(node)
   if (node.children and (not poped)):
    stack.append((node, index))
    index = 0
    node = node.children[0]
   else:
    index += 1
    try:
     node = stack[(-1)][0].children[index]
    except IndexError:
     node = None
  else:
   node = None
  poped = 0
  if ((node is None) and (len(stack) > 1)):
   (node, index) = stack.pop()
   poped = 1
 return l

def pre_order_list ( node , filter_func = no_filter ) : ( l , stack ) = ( [ ] , [ ] ) ( poped , index ) = ( 0 , 0 ) while node : if filter_func ( node ) : if ( not poped ) : l . append ( node ) if ( node . children and ( not poped ) ) : stack . append ( ( node , index ) ) index = 0 node = node . children [ 0 ] else : index += 1 try : node = stack [ ( - 1 ) ] [ 0 ] . children [ index ] except IndexError : node = None else : node = None poped = 0 if ( ( node is None ) and ( len ( stack ) > 1 ) ) : ( node , index ) = stack . pop ( ) poped = 1 return l
create a list with tree nodes for which the <filter> function returned true in a pre order fashion .