def weekdays_to_string(days):
    day_indexes = {name: i for i, name in enumerate(calendar.day_name)}
indexes = [day_indexes[d] for d in days]
ends = [(i + 1) for i in range(len(indexes)) if indexes[(i + 1) % len(
    indexes)] % 7 != (indexes[i % len(indexes)] + 1) % 7]
split = ends[-1]
if split != len(days):
    days = days[split:] + days[:split]
ends = [(len(days) - split + end) for end in ends]
spans = [days[begin:end] for begin, end in zip([0] + ends, ends)]
words = []
for span in spans:
    if len(span) < 3:
        words.extend(span)
else:
    words.append('%s to %s' % (span[0], span[-1]))
if len(days) == 1:
    return words[0]
elif len(days) == 2:
    return '%s and %s' % tuple(words)
else:
    return ', '.join(words)
Python: преобразование («понедельник», «вторник», «среда») в «с понедельника по среду»