Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement