1 | initial version |
Yes, you are right: map
no longer returns a list
but rather an iterator. So you can do e.g.:
def tree(expr):
if expr.operator() is None:
return expr
else:
return [expr.operator()]+list(map(tree, expr.operands()))
2 | No.2 Revision |
Yes, you are right: map
no longer returns a list
but rather an iterator. So you can do e.g.:
def tree(expr):
if expr.operator() is None:
return expr
else:
return [expr.operator()]+list(map(tree, expr.operands()))
You can also avoid map and write a list comprehension instead:
def tree(expr):
if expr.operator() is None:
return expr
else:
return [expr.operator()]+[tree(op) for op in expr.operands()]