<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def find_contour_file(rtdc_dataset):
 """Tries to find a contour file that belongs to an RTDC dataset Returns None if no contour file is found. """

        cont_id = rtdc_dataset.path.stem
        cands = [c.name for c in rtdc_dataset._fdir.rglob("*_contours.txt")]
        cands = sorted(cands)
        # Search for perfect matches, e.g.
        # - M1_0.240000ul_s.tdms
        # - M1_0.240000ul_s_contours.txt
        for c1 in cands:
            if c1.startswith(cont_id):
                cfile = rtdc_dataset._fdir / c1
                break
        else:
            # Search for M* matches with most overlap, e.g.
            # - M1_0.240000ul_s.tdms
            # - M1_contours.txt
            for c2 in cands:
                if (c2.split("_")[0] == rtdc_dataset._mid):
                    # Do not confuse with M10_contours.txt
                    cfile = rtdc_dataset._fdir / c2
                    break
            else:
                msg = "No contour data found for {}".format(rtdc_dataset)
                warnings.warn(msg, NoContourDataWarning)
                cfile = None
        return cfile