Advertisement
STANAANDREY

lsd8 ex5

Nov 18th, 2022
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. binary_tree = { "value" : 1, "left":
  2.             {
  3.                 "value": 7, "left": None, "right":
  4.                 {
  5.                     "value": 1, "left":
  6.                     {
  7.                         "value": 5, "left": None, "right": None
  8.                     }, "right":
  9.                     {
  10.                         "value":121, "left": None, "right": None
  11.                     },
  12.                 },
  13.             }, "right":
  14.                 {
  15.                     "value": 5, "left": None, "right": None
  16.                 }
  17.         }
  18.  
  19. def check_node_cond(tree, f):
  20.     if tree == None:
  21.         return False
  22.  
  23.     ok = f(tree['value'])
  24.     ok = ok or check_node_cond(tree["left"], f)
  25.     ok = ok or check_node_cond(tree["right"], f)
  26.     return ok
  27.  
  28. print(check_node_cond(binary_tree, lambda x: x % 2 == 0))
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement