Advertisement
This is comment for paste
ranges-2
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ParseRange:
- def __init__(self, ranges_string):
- self.ranges_string = ranges_string
- self.numbers = []
- self.ranges = self.ranges_string.split(',')
- def parse_ranges(self):
- for r in self.ranges:
- start, end = map(int, r.split('-'))
- self.numbers.extend(range(start, end + 1))
- return self.numbers
- parser = ParseRange('1-2,8-15,23-25')
- print(parser.parse_ranges())
- parser = ParseRange('0-0, 4-8, 20-20, 43-45')
- print(parser.parse_ranges())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement