Advertisement
lerakaneva

parse_links

Mar 30th, 2021
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import re
  2.  
  3. result = []
  4. tosplit = "1, 3-10,20—23 , 40, 50 - 52"
  5. tosplit.replace(" ", "")
  6. for el in tosplit.split(","):
  7.     links = re.split('-|—', el)
  8.     if len(links) == 0:
  9.         continue
  10.     elif len(links) == 1:
  11.         result.append(int(links[0]))
  12.     elif len(links) == 2:
  13.         for link in range(int(links[0]), int(links[1]) + 1):
  14.             result.append(link)
  15.     else:
  16.         raise ValueError('Bad link')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement