def preorder_traversal(task):
 for item in task:
  if istask(item):
   for i in preorder_traversal(item):
    (yield i)
  elif isinstance(item, list):
   (yield list)
   for i in preorder_traversal(item):
    (yield i)
  else:
   (yield item)

def preorder_traversal ( task ) : for item in task : if istask ( item ) : for i in preorder_traversal ( item ) : ( yield i ) elif isinstance ( item , list ) : ( yield list ) for i in preorder_traversal ( item ) : ( yield i ) else : ( yield item )
a generator to preorder-traverse a task .