def display_list_by_prefix ( names_list , starting_spaces = 0 ) : cur_prefix , result_lines = None , [ ] space = " " * starting_spaces for name in sorted ( names_list ) : split = name . split ( "_" , 1 ) prefix = split [ 0 ] if cur_prefix != prefix : result_lines . append ( space + prefix + ":" ) cur_prefix = prefix result_lines . append ( space + "  * " + name ) return "\n" . join ( result_lines )
list of prefixes and show as headers python
Creates a help string for names_list grouped by prefix .
def display_list_by_prefix(names_list, starting_spaces=0):
  """Creates a help string for names_list grouped by prefix."""
  cur_prefix, result_lines = None, []
  space = " " * starting_spaces
  for name in sorted(names_list):
    split = name.split("_", 1)
    prefix = split[0]
    if cur_prefix != prefix:
      result_lines.append(space + prefix + ":")
      cur_prefix = prefix
    result_lines.append(space + "  * " + name)
  return "\n".join(result_lines)