Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- result = []
- tosplit = "1, 3-10,20—23 , 40, 50 - 52"
- tosplit.replace(" ", "")
- for el in tosplit.split(","):
- links = re.split('-|—', el)
- if len(links) == 0:
- continue
- elif len(links) == 1:
- result.append(int(links[0]))
- elif len(links) == 2:
- for link in range(int(links[0]), int(links[1]) + 1):
- result.append(link)
- else:
- raise ValueError('Bad link')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement