Same fringe: Difference between revisions

→‎{{header|Python}}: Fix adjustments of imports for Python 3.x as well as 2.x. Add-back needed fillvalue!
(→‎{{header|Python}}: Fix adjustments of imports for Python 3.x as well as 2.x. Add-back needed fillvalue!)
Line 39:
This example traverses each tree in step like in the Perl 6 example and will stop at the first miss-match without necessarily completing tree traversals and comparisons.
<lang python>try:
from itertools import zip_longest as izip_longest # Python 3.x
except:
from itertools import izip_longest # Python 2.x
try:
from itertools import izip_longest
except:
zip_longest = lambda *args: map(None, *args)
 
def fringe(tree):
Line 56 ⟶ 53:
def samefringe(tree1, tree2):
return all(node1 == node2
for node1, node2 in zip_longestizip_longest(fringe(tree1), fringe(tree2), fillvalue=None))
 
if __name__ == '__main__':
Anonymous user