How do I convert tuple of tuples to list in one line (pythonic)?
- by ThinkCode
query = 'select mydata from mytable'
cursor.execute(query)
myoutput = cursor.fetchall()
print myoutput
(('aa',), ('bb',), ('cc',))
Why is it (cursor.fetchall) returning a tuple of tuples instead of a tuple since my query is asking for only one column of data?
What is the best way of converting it to ['aa', 'bb', 'cc'] ?
I can do something like this :
mylist = []
myoutput = list(myoutput)
for each in myoutput:
mylist.append(each[0])
I am sure this isn't the best way of doing it. Please enlighten me!