I'd inline things here:

    return re.sub('\s+', ' ', ranges.strip())