Guest User

Untitled

a guest
May 27th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. def count_files(tree_el):
  2.        
  3.     case = FileTreeVisitor()
  4.    
  5.     @case(Root)
  6.     def root(tree_el):
  7.         return reduce(lambda a, b: a + count_files(b), tree_el.childs, 0)
  8.        
  9.     @case(Folder)
  10.     def folder(tree_el):
  11.         return reduce(lambda a, b: a + count_files(b), tree_el.childs, 0)
  12.    
  13.     @case(File)
  14.     def file(tree_el):
  15.         return 1
  16.            
  17.     return case.apply(tree_el)
Add Comment
Please, Sign In to add comment