title: Having trouble with this recursive function
body: <p>See the function below. What I want this to do is take any string I send it, search for the '[' and ']' characters. If they exist, this portion of text is split out, the brackets are removed and it's turned into a dict. I then try to match any of the values from the dict to the attrs list. If there is a match, this value is then inserted back into the original string, and we call the function again with the new string. The conditional then checks if there are more brackets, and if not, the new string is returned.</p>
  
  <p>But when I run the code, the value I get back for text1 is None. I put the print statement in the else clause to see what's coming through there, and the new string is printed as I would expect, but this string isn't getting passed back in the return statement. </p>
  
  <p>When I call the function with text2, which is an identical string to the one I'm expecting text1 to hold, the value is indeed the original string assigned to string2.</p>
  
  <pre><code>import ast
  
  string1 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit [{'do':'said', 'eiusmod':'tempor', 'incididun':'ut'}]"
  
  string2 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"
  
  
  
  def formatter(content):
      if content.find('[') &gt;= 0:
          attrs = ['do', 'fum']
          ind, indend = content.find('['), content.find(']')
          choice = ast.literal_eval(content[ind+1:indend])
          for attr in attrs:
              for key, value in choice.iteritems():
                  if attr == key:
                      new_choice = choice[key]
                      new_string = content[:ind] + new_choice + content[indend+1:]
                      formatter(new_string)
      else:
          return content
  
  text1 = formatter(string1)
  text2 = formatter(string2)
  print text1
  print text2
  </code></pre>