Advertisement
Nenogzar
May 30th, 2024
28
0
Never
This is comment for paste ranges-2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ParseRange:
  2.     def __init__(self, ranges_string):
  3.         self.ranges_string = ranges_string
  4.         self.numbers = []
  5.         self.ranges = self.ranges_string.split(',')
  6.  
  7.     def parse_ranges(self):
  8.         for r in self.ranges:
  9.             start, end = map(int, r.split('-'))
  10.             self.numbers.extend(range(start, end + 1))
  11.         return self.numbers
  12.  
  13.  
  14. parser = ParseRange('1-2,8-15,23-25')
  15. print(parser.parse_ranges())
  16.  
  17. parser = ParseRange('0-0, 4-8, 20-20, 43-45')
  18. print(parser.parse_ranges())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement