Copying and modifying a list of tuples
<p>I'm attempting to rebuild a SQL table by creating a list of tuples from a query, creating a new list of tuples with the data I need changed, then inserting that list of tuples back into SQL. I seem to have everything down except for one part thing. When I recreate the list, there could be any number of columns in the SQL query, and I need to compensate for that. The only value that needs to change is the first in each tuple. Here is the code I have so far:</p>

<pre><code>import pymysql

cnx=pymysql.connect(dbstuff)  
cursor=cnx.cursor()
cursor.execute("SELECT * FROM og_tbl ORDER BY ip_addr,Port ASC")
results=cursor.fetchall()

i=1
list=[]
for line in results:
    list.append((i,line[1:]))
    i += 1
values = ', '.join(map(str,list))
query="INSERT INTO tmp_tbl VALUES {}".format(values)
cursor.execute(query)
cnx.commit()
cnx.close()
</code></pre>

<p>This gives me the results of each tuple that looks like the following. I can't figure out how to do this differently so that the parentheses are only on the outside of each tuple.</p>

<blockquote>
  <p>(1, (sqlstuff)),(2, (sqlstuff)), etc</p>
</blockquote>