nodes: 0, module; 1, function_definition; 2, function_name:get_parameter_value_from_file_names; 3, parameters; 4, block; 5, identifier:files; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:#     unique=False; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, if_statement; 15, expression_statement; 16, for_statement; 17, expression_statement; 18, for_statement; 19, return_statement; 20, identifier:parameters; 21, None; 22, identifier:unique; 23, False; 24, identifier:sort; 25, True; 26, comment:"""
      Takes a list of files, searches for the parameter name in the file name and returns a ordered dict with the file name
      in the first dimension and the corresponding parameter value in the second.
      The file names can be sorted by the parameter value, otherwise the order is kept. If unique is true every parameter is unique and
      mapped to the file name that occurred last in the files list.
  
      Parameters
      ----------
      files : list of strings
      parameter : string or list of strings
      unique : bool
      sort : bool
  
      Returns
      -------
      collections.OrderedDict
  
      """; 27, call; 28, assignment; 29, comparison_operator:parameters is None; 30, comment:# special case, no parameter defined; 31, block; 32, call; 33, block; 34, assignment; 35, identifier:_; 36, identifier:parameters; 37, block; 38, assignment; 39, identifier:one_file; 40, identifier:files; 41, block; 42, call; 43, attribute; 44, argument_list; 45, identifier:files_dict; 46, call; 47, identifier:parameters; 48, None; 49, return_statement; 50, identifier:isinstance; 51, argument_list; 52, expression_statement; 53, identifier:search_string; 54, call; 55, expression_statement; 56, identifier:result; 57, dictionary; 58, expression_statement; 59, if_statement; 60, attribute; 61, argument_list; 62, identifier:logging; 63, identifier:debug; 64, binary_operator:'Get the parameter: ' + str(parameters) + ' values from the file names of ' + str(len(files)) + ' files'; 65, attribute; 66, argument_list; 67, identifier:files_dict; 68, identifier:parameters; 69, identifier:basestring; 70, assignment; 71, attribute; 72, argument_list; 73, augmented_assignment; 74, assignment; 75, identifier:parameter_values; 76, block; 77, identifier:collections; 78, identifier:OrderedDict; 79, conditional_expression:sorted(result.iteritems(), key=itemgetter(1)) if sort else files_dict; 80, binary_operator:'Get the parameter: ' + str(parameters) + ' values from the file names of ' + str(len(files)); 81, string; 82, identifier:collections; 83, identifier:OrderedDict; 84, identifier:parameters; 85, tuple; 86, string; 87, identifier:join; 88, identifier:parameters; 89, identifier:search_string; 90, string; 91, identifier:parameter_values; 92, call; 93, if_statement; 94, expression_statement; 95, comment:# convert string value to list with int; 96, expression_statement; 97, if_statement; 98, call; 99, identifier:sort; 100, identifier:files_dict; 101, binary_operator:'Get the parameter: ' + str(parameters) + ' values from the file names of '; 102, call; 103, string_content:files; 104, identifier:parameters; 105, string_content:_; 106, string_content:_(-?\d+); 107, attribute; 108, argument_list; 109, call; 110, block; 111, assignment; 112, assignment; 113, identifier:unique; 114, comment:# reduce to the files with different scan parameters; 115, block; 116, else_clause; 117, identifier:sorted; 118, argument_list; 119, binary_operator:'Get the parameter: ' + str(parameters); 120, string; 121, identifier:str; 122, argument_list; 123, identifier:re; 124, identifier:findall; 125, identifier:search_string; 126, identifier:one_file; 127, identifier:isinstance; 128, argument_list; 129, expression_statement; 130, identifier:parameter_values; 131, list_comprehension; 132, subscript; 133, call; 134, for_statement; 135, block; 136, call; 137, keyword_argument; 138, string; 139, call; 140, string_content:values from the file names of; 141, call; 142, subscript; 143, identifier:tuple; 144, assignment; 145, list; 146, for_in_clause; 147, identifier:files_dict; 148, identifier:one_file; 149, identifier:dict; 150, argument_list; 151, pattern_list; 152, call; 153, block; 154, expression_statement; 155, attribute; 156, argument_list; 157, identifier:key; 158, call; 159, string_content:Get the parameter:; 160, identifier:str; 161, argument_list; 162, identifier:len; 163, argument_list; 164, identifier:parameter_values; 165, integer:0; 166, identifier:parameter_values; 167, call; 168, call; 169, identifier:i; 170, identifier:parameter_values; 171, call; 172, identifier:key; 173, identifier:value; 174, attribute; 175, argument_list; 176, if_statement; 177, assignment; 178, identifier:result; 179, identifier:iteritems; 180, identifier:itemgetter; 181, argument_list; 182, identifier:parameters; 183, identifier:files; 184, identifier:list; 185, argument_list; 186, identifier:int; 187, argument_list; 188, identifier:zip; 189, argument_list; 190, identifier:files_dict; 191, identifier:items; 192, comparison_operator:value not in result.values(); 193, block; 194, subscript; 195, subscript; 196, integer:1; 197, call; 198, identifier:i; 199, identifier:parameters; 200, identifier:parameter_values; 201, identifier:value; 202, call; 203, expression_statement; 204, identifier:result; 205, identifier:one_file; 206, identifier:files_dict; 207, identifier:one_file; 208, identifier:reduce; 209, argument_list; 210, attribute; 211, argument_list; 212, assignment; 213, lambda; 214, identifier:parameter_values; 215, identifier:result; 216, identifier:values; 217, subscript; 218, identifier:value; 219, lambda_parameters; 220, binary_operator:t1 + t2; 221, identifier:result; 222, identifier:key; 223, identifier:t1; 224, identifier:t2; 225, identifier:t1; 226, identifier:t2
code: def get_parameter_value_from_file_names(files, parameters=None, unique=False, sort=True):
      """
      Takes a list of files, searches for the parameter name in the file name and returns a ordered dict with the file name
      in the first dimension and the corresponding parameter value in the second.
      The file names can be sorted by the parameter value, otherwise the order is kept. If unique is true every parameter is unique and
      mapped to the file name that occurred last in the files list.
  
      Parameters
      ----------
      files : list of strings
      parameter : string or list of strings
      unique : bool
      sort : bool
  
      Returns
      -------
      collections.OrderedDict
  
      """
  #     unique=False
      logging.debug('Get the parameter: ' + str(parameters) + ' values from the file names of ' + str(len(files)) + ' files')
      files_dict = collections.OrderedDict()
      if parameters is None:  # special case, no parameter defined
          return files_dict
      if isinstance(parameters, basestring):
          parameters = (parameters, )
      search_string = '_'.join(parameters)
      for _ in parameters:
          search_string += r'_(-?\d+)'
      result = {}
      for one_file in files:
          parameter_values = re.findall(search_string, one_file)
          if parameter_values:
              if isinstance(parameter_values[0], tuple):
                  parameter_values = list(reduce(lambda t1, t2: t1 + t2, parameter_values))
              parameter_values = [[int(i), ] for i in parameter_values]  # convert string value to list with int
              files_dict[one_file] = dict(zip(parameters, parameter_values))
              if unique:  # reduce to the files with different scan parameters
                  for key, value in files_dict.items():
                      if value not in result.values():
                          result[key] = value
              else:
                  result[one_file] = files_dict[one_file]
      return collections.OrderedDict(sorted(result.iteritems(), key=itemgetter(1)) if sort else files_dict)