def clean(self):
        """
        Clean ranges list, combining adjacent ranges
        """

        self.ranges.sort()

        oldl, oldh = None, None
        for i,(l, h) in enumerate(self.ranges):
            if l is None:
                continue
            # l is >= oldl and h is >= oldh due to sort()
            if oldl is not None and l <= oldh + 1:
                l = oldl
                h = max(oldh, h)
                self.ranges[i - 1] = None
                self.ranges[i] = (l, h)

            oldl, oldh = l, h

        self.ranges = filter(None, self.ranges)
dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/twisted/mail/imap4.py/MessageSet.clean/original