Working with dictionaries and data to and from database - Python 3
<p>I have a data which looks like (as example) - </p>

<pre><code>{"phone_number": "XXX1","phone_number_country": "XXX2","text": "XXX2"}
</code></pre>

<p>where XXX is my data (it can be different types of data)</p>

<p>Also, I have DB with data, which looks like (as example) - 
[<img src="http://i.stack.imgur.com/41UE4.png" alt="DB"></p>

<p>Data is taken from DB:</p>

<pre><code>con = sqlite3.connect('dab')
cur = con.cursor()
c = cur.execute('SELECT * FROM some')
u_data = c.fetchall()
</code></pre>

<p>Each row is a set of data.</p>

<p>The data is taken from the first row and data from <strong>column_1</strong> goes to the place of <strong>XXX1</strong>, data from <strong>column_2</strong> goes to the place of <strong>XXX2</strong> and data from <strong>column_3</strong> goes to the place of <strong>XXX3</strong>... </p>

<p>After that I should get the data from the original array (template) + data taken from the database...then this dict should be committed to DB and the loop should go on until the data from the DB and every time commit my new dict to DB...</p>

<p>Now I have some code:</p>

<pre><code>import sqlite3
from itertools import product

a = {"phone_number": "XXX","phone_number_country": "XXX","text": "XXX"}

con = sqlite3.connect('dab')
cur = con.cursor()
c = cur.execute('SELECT * FROM some')
u_data = c.fetchall()
s = list(u_data)
b = list(zip(*u_data))
out = product(*b)
tout =list(out)
i = 0
for elem in b:
  b[i] = elem
  a["phone_number"] = elem[0]
  a["phone_number_country"] = elem[1]
  a["text"] = elem[2]
  print(a)
</code></pre>

<p>and in console i have this:</p>

<pre><code>{'text': 'phone_number31', 'phone_number_country': 'phone_number21', 'phone_number': 'phone_number11'}
{'text': 'phone_number_c32', 'phone_number_country': 'phone_number_c22', 'phone_number': 'phone_number_c12'}
{'text': 'text33', 'phone_number_country': 'text23', 'phone_number': 'text13'}
</code></pre>

<p>It should be:</p>

<pre><code>{"phone_number": "phone_number11","phone_number_country": "phone_number_c12","text": "text13"}
{"phone_number": "phone_number21","phone_number_country": "phone_number_c22","text": "text23"}
{"phone_number": "phone_number31","phone_number_country": "phone_number_c32","text": "text33"}
</code></pre>

<p>Answer here:</p>

<pre><code>a = {"phone_number": "XXX","phone_number_country": "XXX","text": "XXX"}

con = sqlite3.connect('dab')
cur = con.cursor()
c = cur.execute('SELECT * FROM some')
u_data = c.fetchall()
s = list(u_data)
i = 0
for elem in s:
    s[i] = elem
    a["phone_number"] = elem[0]
    a["phone_number_country"] = elem[1]
    a["text"] = elem[2]
</code></pre>

python arrays database