title: How to elegantly transform '1-3,6-8' to '1 2 3 6 7 8' within a list?
body: <h1>Problem</h1>
  
  <p><strong>Background:</strong></p>
  
  <p>I have a list of ~10,000 lists containing irregular data which needs to be transformed to a specific format. This data will be ingested into a pandas dataframe after transformation.</p>
  
  <p><strong>TL/DR;</strong> How to elegantly transform matched strings of the following regex in a list?</p>
  
  <p><strong>Regex</strong>
  '\d{1,3}-\d{1,3},\d{1,3}-\d{1,3}'</p>
  
  <p><strong>Example:</strong>
  '1-3,6-8' to '1 2 3 6 7 8' </p>
  
  <p><strong>Current Solution:</strong>
  Using list comprehensions required multiple type casts to transform the string and is unfit to be a lasting solution.</p>
  
  <pre><code>pat = re.compile('\d{1,3}-\d{1,3},\d{1,3}-\d{1,3}')
  
  row = ['sss-www,ddd-eee', '1-3,6-8', 'XXXX', '0-2,3-7','234','1,5']
  
  lst = [((str(list(range(int(x.split(',')[0].split('-')[0]), 
      int(x.split(','[0].split('-')[1])+1))).strip('[]').replace(',', '')+' '
      +str(list(range(int(x.split(',')[1].split('-')[0]), 
      int(x.split(',')[1].split('-')[1]) + 1))).strip('[]').replace(',', ''))) 
      if pat.match(str(x)) else x for x in row]
  </code></pre>
  
  <p><strong>Result</strong> </p>
  
  <pre><code>    ['sss-www,ddd-eee', '1 2 3 6 7 8', 'XXXX', '0 1 2 3 4 5 6 7', '234', '1,5']
  </code></pre>