Advertisement
go6odn28

ranges

May 30th, 2024
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. ranges_str = '1-2,8-15,23-25'
  2. ranges_list = ranges_str.split(',')
  3. result = []
  4.  
  5. for record in ranges_list:
  6.     start, end = map(int, record.split('-'))
  7.     for num in range(start, end + 1):
  8.         result.append(num)
  9.  
  10. print(result)
  11. # [1, 2, 8, 9, 10, 11, 12, 13, 14, 15, 23, 24, 25]
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement