title: storing formatting in a python dictionary
body: <p>Hopefully I'm not missing something obvious...</p>
  
  <p>I'm creating a function that will ease in creating specifically formatted JSON data from a Django query. However, this should be a purely python question.</p>
  
  <p>I'd like to be able to convert all values with a given index to a specified format with a function like the folowing:</p>
  
  <pre><code>data = [['foo1','bar1'],['foo2','bar2']]
  format = {1:'VALUE says Hello world'}
  
  &gt;&gt; some_function(data, format) 
  [['foo1','bar1 says Hello World'],['foo2','bar2 says Hello World']]
  </code></pre>
  
  <p>Basic idea:</p>
  
  <pre><code>def some_function(data, format):
      for row in data:
          for count, value in enumerate(row):
              if format.has_key(count):
                  #do something to replace 'VALUE' with value
              else:
                  #just use value, no changes
      return formatted_data
  </code></pre>
  
  <p>The root of this question is that the data goes directly to web and I'd like to define specific formatting based on what I'm passing through the generic function.</p>
  
  <p>Edit for clarity:</p>
  
  <p><strong>What should I add to <code>some_function()</code> to convert the appropriate values in the data list to the format defined by the format dictionary?</strong></p>