title: How to change a function based on the length of an input variable
body: <p>I have written a function that scans a list of strings by index for regex matches in the current and next two indexes of the list. If a match is found across three indexes, those elements in the list are joined.</p>
  
  <pre><code>import re
  from nltk.tokenize import MWETokenizer
  
  s = ['Here','be', 'dragons', 'Captain', '23', 'March', '2018', 'and', 'Oct', '22', '2018']
  pattern = [r'\d{2}|[a-zA-Z]{3,5}', r'\d{2}|[a-zA-Z]{3,5}', r'\d{4}']
  
  def un_tokenize(pattern, sep, toks):
      tokenizer = MWETokenizer([], separator=sep)
      for i in list(range(0, len(toks)-len(pattern)+1)):
          if bool(re.match(pattern[0], toks[i])) and \
             bool(re.match(pattern[1], toks[i+1])) and \
             bool(re.match(pattern[2], toks[i+2])):
  
             tup = (toks[i], toks[i+1], toks[i+2])
             tokenizer.add_mwe(tup)
      return tokenizer.tokenize(toks)
  
  
  print(un_tokenize(pattern, '+', s))
  </code></pre>
  
  <p>which correctly returns</p>
  
  <blockquote>
    <p>['Here', 'be', 'dragons', 'Captain', '23+March+2018', 'and', 'Oct+22+2018']</p>
  </blockquote>
  
  <p>I want to know,
  1) How can I change the if statement to include a variable number of 'and's, so that I can put in a pattern of 2 regexes or 4 regexes etc.?</p>
  
  <p>2) I am sure this is not the most pythonic way of doing this, so I other methods are welcome.</p>