Help me fix my code, it is not working correctly for the index section, since it doesn't remove the whitespaces:

metadata_str = """# Información de la tabla

* BASE DE DATOS: {database_name}
* NOMBRE TABLA: {table_name}
* TIPO DE LOCKEO: {lock_type}

---
## Metadata de la tabla
column_name | type | DESCRIPCION | TIPO_RELACION | CAMPO | status | length
-- | -- | -- | -- | -- | -- | --
{column_1_name}  | {column_1_type} |  {column_1_description}  |  {column_1_relation_type}  |  {column_1_field}  |  {column_1_status}  |  {column_1_length}
{column_2_name}  | {column_2_type} |  {column_2_description}  |  {column_2_relation_type}  |  {column_2_field}  |  {column_2_status}  |  {column_2_length}
{column_3_name}  | {column_3_type} |  {column_3_description}  |  {column_3_relation_type}  |  {column_3_field}  |  {column_3_status}  |  {column_3_length}
{column_4_name}  | {column_4_type} |  {column_4_description}  |  {column_4_relation_type}  |  {column_4_field}  |  {column_4_status}  |  {column_4_length}
{column_5_name}  | {column_5_type} |  {column_5_description}  |  {column_5_relation_type}  |  {column_5_field}  |  {column_5_status}  |  {column_5_length}
{column_6_name}  | {column_6_type} |  {column_6_description}  |  {column_6_relation_type}  |  {column_6_field}  |  {column_6_status}  |  {column_6_length}
{column_7_name}  | {column_7_type} |  {column_7_description}  |  {column_7_relation_type}  |  {column_7_field}  |  {column_7_status}  |  {column_7_length}
{column_8_name}  | {column_8_type} |  {column_8_description}  |  {column_8_relation_type}  |  {column_8_field}  |  {column_8_status}  |  {column_8_length}
{column_9_name}  | {column_9_type} |  {column_9_description}  |  {column_9_relation_type}  |  {column_9_field}  |  {column_9_status}  |  {column_9_length}
{column_10_name}  | {column_10_type} |  {column_10_description}  |  {column_10_relation_type}  |  {column_10_field}  |  {column_10_status}  |  {column_10_length}
{column_11_name}  | {column_11_type} |  {column_11_description}  |  {column_11_relation_type}  |  {column_11_field}  |  {column_11_status}  |  {column_11_length}
{column_12_name}  | {column_12_type} |  {column_12_description}  |  {column_12_relation_type}  |  {column_12_field}  |  {column_12_status}  |  {column_12_length}
{column_13_name}  | {column_13_type} |  {column_13_description}  |  {column_13_relation_type}  |  {column_13_field}  |  {column_13_status}  |  {column_13_length}
{column_14_name}  | {column_14_type} |  {column_14_description}  |  {column_14_relation_type}  |  {column_14_field}  |  {column_14_status}  |  {column_14_length}
{column_15_name}  | {column_15_type} |  {column_15_description}  |  {column_15_relation_type}  |  {column_15_field}  |  {column_15_status}  |  {column_15_length}
{column_16_name}  | {column_16_type} |  {column_16_description}  |  {column_16_relation_type}  |  {column_16_field}  |  {column_16_status}  |  {column_16_length}
{column_17_name}  | {column_17_type} |  {column_17_description}  |  {column_17_relation_type}  |  {column_17_field}  |  {column_17_status}  |  {column_17_length}
{column_18_name}  | {column_18_type} |  {column_18_description}  |  {column_18_relation_type}  |  {column_18_field}  |  {column_18_status}  |  {column_18_length}
{column_19_name}  | {column_19_type} |  {column_19_description}  |  {column_19_relation_type}  |  {column_19_field}  |  {column_19_status}  |  {column_19_length}
{column_20_name}  | {column_20_type} |  {column_20_description}  |  {column_20_relation_type}  |  {column_20_field}  |  {column_20_status}  |  {column_20_length}
{column_21_name}  | {column_21_type} |  {column_21_description}  |  {column_21_relation_type}  |  {column_21_field}  |  {column_21_status}  |  {column_21_length}
{column_22_name}  | {column_22_type} |  {column_22_description}  |  {column_22_relation_type}  |  {column_22_field}  |  {column_22_status}  |  {column_22_length}
{column_23_name}  | {column_23_type} |  {column_23_description}  |  {column_23_relation_type}  |  {column_23_field}  |  {column_23_status}  |  {column_23_length}
{column_24_name}  | {column_24_type} |  {column_24_description}  |  {column_24_relation_type}  |  {column_24_field}  |  {column_24_status}  |  {column_24_length}
{column_25_name}  | {column_25_type} |  {column_25_description}  |  {column_25_relation_type}  |  {column_25_field}  |  {column_25_status}  |  {column_25_length}

## INDICES
NOMBRE                                   |UNICO       |ORDENAMIENTO                     |CAMPOS
---------------------------------------- |----------- |-------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
{index_1_name}                           |{index_1_unique}      |{index_1_ordering}                        |{index_1_fields}
{index_2_name}                           |{index_2_unique}      |{index_2_ordering}                        |{index_2_fields}
{index_3_name}                           |{index_3_unique}      |{index_3_ordering}                        |{index_3_fields}
"""

# Function to replace multiple consecutive dashes with a single dash
def replace_multiple_dashes(line):
    while '--' in line:
        line = line.replace('--', '-')
    return line

# Extract the relevant part of the string
metadata_lines = metadata_str.splitlines()
start_index = next(i for i, line in enumerate(metadata_lines) if line.startswith("column_name"))
indices_index = next(i for i, line in enumerate(metadata_lines) if line.startswith("## INDICES"))

# Process metadata part
metadata_part = metadata_lines[start_index:indices_index]
cleaned_metadata_lines = [replace_multiple_dashes(line.strip().replace("  ", " ")) for line in metadata_part if line.strip()]

# Process indices part
indices_part = metadata_lines[indices_index:]
cleaned_indices_lines = [replace_multiple_dashes(line.strip().replace("  ", " ")) for line in indices_part if line.strip()]

# Join the cleaned lines back into a single string
cleaned_metadata_str = "\n".join(cleaned_metadata_lines + cleaned_indices_lines)

print(cleaned_metadata_str)