0

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.

1
  • tuple(xs) will convert any list (or rather, iterable) xs to a tuple. Commented Jul 3, 2020 at 23:23

1 Answer 1

1

You could try with this:

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

tmpArray=[tuple(tmpArray)]
print(tmpArray)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.