<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def calculate_mass(composition, mass_data=None):
 """Calculates the monoisotopic mass of a composition Parameters composition : Mapping Any Mapping type where keys are element symbols and values are integers mass_data : dict, optional A dict with the masses of the chemical elements (the default value is :py:data:`nist_mass`). Returns ------- mass : float """

    mass = 0.0
    if mass_data is None:
        mass_data = nist_mass
    for element in composition:
        try:
            mass += (composition[element] * mass_data[element][0][0])
        except KeyError:
            match = re.search(r"(\S+)\[(\d+)\]", element)
            if match:
                element_ = match.group(1)
                isotope = int(match.group(2))
                mass += composition[element] * mass_data[element_][isotope][0]
            else:
                raise
    return mass