A Matter of Flexibility: Index Variables vs. Constants
<p>Consider the following hypothetical situation.</p>

<p>As part of an application you are developing in python, you must format a list of objects and assign each subsequent item to a provided keyword as a tuple. Here is the syntax:</p>

<pre><code>entries = [keyword, [obj1, obj2, obj3, ...]]    # Original list of object entries

formatted = [(keyword, obj1), (keyword, obj2), (keyword, obj3), ...]
</code></pre>

<p>Here is the function that you propose (let me know if this can be more efficient):</p>

<pre><code>def format(keyword, entries):
    return [(keyword, x) for x in entries[1][0]]
</code></pre>

<p>Here is the function applied:</p>

<pre><code>foo = format(entries[0], entries[1])
</code></pre>

<p><strong>Flexibility Question</strong></p>

<p>Notice that the <code>entries</code> variable in the <code>format</code> function has static index integers <code>1</code> and <code>0</code>. Suppose that you anticipate that new terms may potentially be appended to the <code>entries</code> list. Would you normally use index variables instead of constants (expect incrementing constants for later items that will go into the list), and if so, would you use local or global indices? How do you account for this type of flexibility in your code?</p>
