def find_pairs(spec1, spec2, tol, shift=0):
    'Find matching pairs between two spectra.\n\n    Args\n    ----\n    spec1 : list of tuples\n        List of (mz, intensity) tuples.\n    spec2 : list of tuples\n        List of (mz, intensity) tuples.\n    tol : float\n        Tolerance. Peaks will be considered a match when < tol appart.\n    shift : float, optional\n        Shift spectra peaks by shift. The default is 0.\n\n    Returns\n    -------\n    matching_pairs : list\n        List of found matching peaks.\n\n    '
    spec1 = spec1[np.lexsort((spec1[:, 1], spec1[:, 0])), :]
    spec2 = spec2[np.lexsort((spec2[:, 1], spec2[:, 0])), :]
    matching_pairs = []
    spec2lowpos = 0
    spec2length = len(spec2)
    for idx in range(len(spec1)):
        mz = spec1[(idx, 0)]
        intensity = spec1[(idx, 1)]
        while ((spec2lowpos < spec2length) and ((spec2[spec2lowpos][0] + shift) < (mz - tol))):
            spec2lowpos += 1
        if (spec2lowpos == spec2length):
            break
        spec2pos = spec2lowpos
        while ((spec2pos < spec2length) and ((spec2[spec2pos][0] + shift) < (mz + tol))):
            matching_pairs.append((idx, spec2pos, (intensity * spec2[spec2pos][1])))
            spec2pos += 1
    return matching_pairs
Find matching pairs between two spectra.

Args
----
spec1 : list of tuples
    List of (mz, intensity) tuples.
spec2 : list of tuples
    List of (mz, intensity) tuples.
tol : float
    Tolerance. Peaks will be considered a match when < tol appart.
shift : float, optional
    Shift spectra peaks by shift. The default is 0.

Returns
-------
matching_pairs : list
    List of found matching peaks.
def find_pairs(spec1, spec2, tol, shift=0):
    'Find matching pairs between two spectra.\n\n    Args\n    ----\n    spec1 : list of tuples\n        List of (mz, intensity) tuples.\n    spec2 : list of tuples\n        List of (mz, intensity) tuples.\n    tol : float\n        Tolerance. Peaks will be considered a match when < tol appart.\n    shift : float, optional\n        Shift spectra peaks by shift. The default is 0.\n\n    Returns\n    -------\n    matching_pairs : list\n        List of found matching peaks.\n\n    '
    spec1 = spec1[np.lexsort((spec1[:, 1], spec1[:, 0])), :]
    spec2 = spec2[np.lexsort((spec2[:, 1], spec2[:, 0])), :]
    matching_pairs = []
    spec2lowpos = 0
    spec2length = len(spec2)
    for idx in range(len(spec1)):
        mz = spec1[(idx, 0)]
        intensity = spec1[(idx, 1)]
        while ((spec2lowpos < spec2length) and ((spec2[spec2lowpos][0] + shift) < (mz - tol))):
            spec2lowpos += 1
        if (spec2lowpos == spec2length):
            break
        spec2pos = spec2lowpos
        while ((spec2pos < spec2length) and ((spec2[spec2pos][0] + shift) < (mz + tol))):
            matching_pairs.append((idx, spec2pos, (intensity * spec2[spec2pos][1])))
            spec2pos += 1
    return matching_pairs