def create_title_to_index_dict(mgf_filename):
    """
    Creates a dictionary with the spectrum's title as key and the 0-based index as value.

    :param mgf_filename: The MGF file to parse.
    :return: A dict with the spectra' titles as keys and their 0-based index as value.
    """
    title_to_index = dict()
    with open(mgf_filename, "r") as mgf_file:
        current_spec_index = 0
        for line in mgf_file:
            # ignore non-title lines
            if line.strip()[0:6] != "TITLE=":
                continue

            title = line[6:].strip()
            title_to_index[title] = current_spec_index
            current_spec_index += 1

    return title_to_index