nodes: 0, module; 1, function_definition; 2, function_name:group; 3, parameters; 4, block; 5, identifier:self; 6, identifier:p_todos; 7, expression_statement; 8, comment:# preorder todos for the group sort; 9, expression_statement; 10, comment:# initialize result with a single group; 11, expression_statement; 12, for_statement; 13, comment:# sort all groups; 14, for_statement; 15, return_statement; 16, comment:"""
          Groups the todos according to the given group string.
          """; 17, assignment; 18, assignment; 19, pattern_list; 20, attribute; 21, block; 22, pattern_list; 23, call; 24, block; 25, identifier:result; 26, identifier:p_todos; 27, call; 28, identifier:result; 29, call; 30, tuple_pattern; 31, identifier:_; 32, identifier:self; 33, identifier:groupfunctions; 34, expression_statement; 35, expression_statement; 36, for_statement; 37, identifier:key; 38, identifier:_group; 39, attribute; 40, argument_list; 41, expression_statement; 42, identifier:_apply_sort_functions; 43, argument_list; 44, identifier:OrderedDict; 45, argument_list; 46, identifier:function; 47, identifier:label; 48, assignment; 49, assignment; 50, pattern_list; 51, call; 52, block; 53, identifier:result; 54, identifier:items; 55, assignment; 56, identifier:p_todos; 57, attribute; 58, list; 59, identifier:oldresult; 60, identifier:result; 61, identifier:result; 62, call; 63, identifier:oldkey; 64, identifier:oldgroup; 65, attribute; 66, argument_list; 67, for_statement; 68, subscript; 69, call; 70, identifier:self; 71, identifier:pregroupfunctions; 72, tuple; 73, identifier:OrderedDict; 74, argument_list; 75, identifier:oldresult; 76, identifier:items; 77, pattern_list; 78, call; 79, block; 80, identifier:result; 81, identifier:key; 82, attribute; 83, argument_list; 84, tuple; 85, identifier:p_todos; 86, identifier:key; 87, identifier:_group; 88, identifier:groupby; 89, argument_list; 90, expression_statement; 91, if_statement; 92, for_statement; 93, identifier:self; 94, identifier:sort; 95, identifier:_group; 96, identifier:oldgroup; 97, identifier:function; 98, assignment; 99, not_operator; 100, block; 101, identifier:subkey; 102, identifier:key; 103, block; 104, identifier:newgroup; 105, call; 106, call; 107, expression_statement; 108, expression_statement; 109, expression_statement; 110, if_statement; 111, identifier:list; 112, argument_list; 113, identifier:isinstance; 114, argument_list; 115, assignment; 116, assignment; 117, assignment; 118, comparison_operator:newkey in result; 119, block; 120, else_clause; 121, identifier:_group; 122, identifier:key; 123, identifier:list; 124, identifier:key; 125, list; 126, identifier:subkey; 127, call; 128, identifier:newkey; 129, binary_operator:oldkey + (subkey,); 130, identifier:newkey; 131, identifier:result; 132, expression_statement; 133, block; 134, identifier:key; 135, attribute; 136, argument_list; 137, identifier:oldkey; 138, tuple; 139, assignment; 140, expression_statement; 141, string:"{}: {}"; 142, identifier:format; 143, identifier:label; 144, identifier:subkey; 145, identifier:subkey; 146, subscript; 147, binary_operator:result[newkey] + newgroup; 148, assignment; 149, identifier:result; 150, identifier:newkey; 151, subscript; 152, identifier:newgroup; 153, subscript; 154, identifier:newgroup; 155, identifier:result; 156, identifier:newkey; 157, identifier:result; 158, identifier:newkey
code: def group(self, p_todos):
          """
          Groups the todos according to the given group string.
          """
          # preorder todos for the group sort
          p_todos = _apply_sort_functions(p_todos, self.pregroupfunctions)
  
          # initialize result with a single group
          result = OrderedDict([((), p_todos)])
  
          for (function, label), _ in self.groupfunctions:
              oldresult = result
              result = OrderedDict()
              for oldkey, oldgroup in oldresult.items():
                  for key, _group in groupby(oldgroup, function):
                      newgroup = list(_group)
  
                      if not isinstance(key, list):
                          key = [key]
  
                      for subkey in key:
                          subkey = "{}: {}".format(label, subkey)
                          newkey = oldkey + (subkey,)
  
                          if newkey in result:
                              result[newkey] = result[newkey] + newgroup
                          else:
                              result[newkey] = newgroup
  
          # sort all groups
          for key, _group in result.items():
              result[key] = self.sort(_group)
  
          return result