fork(2) download
  1. #!/usr/bin/python
  2. import re
  3. regex = r"(\d+):((?:\d+[-,]|\d+$)+)"
  4. line = "8:20-24,30,31,32,10:21-24,30,31,32,15:11,12,13-14,16-18"
  5. regex2 = r"\d+-\d+|\d+"
  6.  
  7. d={}
  8.  
  9. matchObj = re.finditer(regex,line, re.MULTILINE)
  10.  
  11. for matchNum, match in enumerate(matchObj):
  12. #print (match.group(2))
  13. match2 = re.finditer(regex2,match.group(2))
  14. for matchNum1, m in enumerate(match2):
  15. key=int(match.group(1))
  16. if '-' in m.group():
  17. y = m.group().split('-')
  18. for i in xrange(int(y[0]),int(y[1])+1):
  19. if key in d:
  20. d[key].append(i)
  21. else:
  22. d[key] = [i,]
  23. else:
  24. if key in d:
  25. d[key].append(int(m.group()))
  26. else:
  27. d[key] = [int(m.group()),]
  28. print(d)
  29.  
Success #stdin #stdout 0s 9024KB
stdin
Standard input is empty
stdout
{8: [20, 21, 22, 23, 24, 30, 31, 32], 10: [21, 22, 23, 24, 30, 31, 32], 15: [11, 12, 13, 14, 16, 17, 18]}