<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _set_medians_and_extremes(self):
 """ Sets median values for rtt and the offset of result packets. """


        rtts = sorted([p.rtt for p in self.packets if p.rtt is not None])
        if rtts:
            self.rtt_min = rtts[0]
            self.rtt_max = rtts[-1]
            self.rtt_median = self.calculate_median(rtts)

        offsets = sorted(
            [p.offset for p in self.packets if p.offset is not None]
        )
        if offsets:
            self.offset_min = offsets[0]
            self.offset_max = offsets[-1]
            self.offset_median = self.calculate_median(offsets)