def select_files_from_tree(file_tree):
 selected = {}
 stack = [file_tree]
 while len(stack):
  file_node = stack.pop(0)
  target_files = [f for f in file_node['children'] if (f['kind'] == 'file')]
  if target_files:
   target_file = target_files[0]
   selected[target_file['extra']['hashes']['sha256']] = target_file
  target_folders = [f for f in file_node['children'] if (f['kind'] == 'folder')]
  if target_folders:
   stack.append(target_folders[0])
 return selected

def select_files_from_tree ( file_tree ) : selected = { } stack = [ file_tree ] while len ( stack ) : file_node = stack . pop ( 0 ) target_files = [ f for f in file_node [ 'children' ] if ( f [ 'kind' ] == 'file' ) ] if target_files : target_file = target_files [ 0 ] selected [ target_file [ 'extra' ] [ 'hashes' ] [ 'sha256' ] ] = target_file target_folders = [ f for f in file_node [ 'children' ] if ( f [ 'kind' ] == 'folder' ) ] if target_folders : stack . append ( target_folders [ 0 ] ) return selected
select a file from every depth of a file_tree .