title: slice a string in python list
body: <p>I want to build a regex from structures like this :</p>
  
  <pre><code>    [['mirna', 'or', 'microrna'], 'or', 'lala']
  </code></pre>
  
  <p>...and I want to extract the left part of the 'or' recursively to build my regex.
  As you can see, sometimes it is another embed list, sometimes it is a string.</p>
  
  <p>My regex should look like :</p>
  
  <pre><code>((mirna|microrna)|lala)
  </code></pre>
  
  <p>So this is my algorithm (recursive because I never know how deep is my structure) :</p>
  
  <pre><code>def _buildRegex(self,  request):
    if not isinstance(request,  str):
      print(request)
      print('request not a str')
      request = request[0]
    for i, e in enumerate(request):
      self._print(i)
      self._print(e)
      if e == 'or':
        self._print('OR found')
        if isinstance(request,  str):
          print('left is str')
          left = request
        else:
          print('left is list')
          left = request[0:i]
  
        if isinstance(request,  str):
          print('right is str')
          right = request
        else:
          print('right is list')
          right = request[i+1:len(request)-1]
        print('(')
  
        if isinstance(left,  list):
          self._buildRegex(left)
        else:
          print(left)
        print('|')
        if isinstance(right,  list):
          self._buildRegex(right)
        else:
          print(left)
        print(')')
  </code></pre>
  
  <p>And this is what I get :</p>
  
  <pre><code>    [[['mirna', 'or', 'microrna'], 'or', 'lala']]
      request not a str
      0
      ['mirna', 'or', 'microrna']
      1
      or
      OR found
      left is list
      right is list
      (
      [['mirna', 'or', 'microrna']]
      request not a str
      0
      mirna
      1
      or
      OR found
      left is list
      right is list
      (
      ['mirna']
      request not a str
      0
      m
      1
      i
      2
      r
      3
      n
      4
      a
      |
      []
      request not a str
  </code></pre>
  
  <p>I guess when I extract the single word the slice transform it into a list.
  But how can I differenciate a final word from a list ?
  I have spend many hours and can't found a solution, I am totally lost.  </p>