yz55
yz55

Reputation: 27

Modify multidimensional array (Python)

I append items from a database to an array, like that (I need the 0 in front):

tmpArray = [0]
sql = "SELECT value FROM employees;"
c.execute(sql)
rows = c.fetchall()
for row in rows:
    tmpArray.append([row[0]])

Output is like that:

tmpArray = [0, ["xxx"], ["yyy"], ["zzz"]]

I need the Array surrounded by brackets like that:

tmpArray = [(0, ["xxx"], ["yyy"], ["zzz"])]

How can I achieve this or how can I modify the current array, so I get the result that I want? Thank you for helping. The script that I want to use needs the data exactly like that.

Upvotes: 0

Views: 56

Answers (1)

MrNobody33
MrNobody33

Reputation: 6483

You could try with this:

tmpArray = [0, ["xxx"], ["yyy"], ["zzz"]]

tmpArray=[tuple(tmpArray)]
print(tmpArray)

Upvotes: 1

Related Questions