from contextlib import suppress
def adv_range(seq):
for element in seq.split(','):
with suppress(ValueError):
if '-' in element:
start, _, stop = element.partition('-')
start, stop = int(start), int(stop)
direction = 1 if start <= stop else -1
yield from range(start, stop + direction, direction)
else:
yield int(element)
def safe_adv_range(seq, constructor=set):
retval = constructor(adv_range(seq))
return sorted(retval)
Comments
0 B
|👍
/👎