def merge_metabolites(list_of_metabolites, base_metabolite):
    """ Merge duplicated metabolites

    Parameters
    ----------
    list_of_metabolites: list
    base_metabolite: GEMEditor.model.classes.cobra.Metabolite

    Returns
    -------
    list
    """
    merged = list()
    for metabolite in list_of_metabolites:
        if metabolite is not base_metabolite:
            for reaction in metabolite.reactions:
                stoichiometry = reaction.metabolites
                coefficient = stoichiometry.pop(metabolite)
                if base_metabolite in stoichiometry:
                    stoichiometry[base_metabolite] += coefficient
                else:
                    stoichiometry[base_metabolite] = coefficient
                reaction.subtract_metabolites(reaction.metabolites, combine
                    =True, reversibly=False)
                reaction.add_metabolites(stoichiometry)
            for evidence in metabolite.evidences.copy():
                evidence.substitute_item(metabolite, base_metabolite)
            base_metabolite.annotation.update(metabolite.annotation)
            merged.append(metabolite)
    if merged and merged[0].model:
        merged[0].model.gem_remove_metabolites(merged)
    return merged
