Split tuple into desired format in Python

I read the data from sqlite3 and the output is similar to (3252, u'https://www.google.fr/search?aq=f&sourceid=chrome&ie=UTF-8&q=python+split+tuple', u'Using the split command in a list - Python', 10)

So, I want to reformat it into a table, for example: table = [["", "number", "url", "title"], ["number", 3252], ["urls", .....], ["title", ....]] So, how can I do this because the split cannot be used for a tuple ... Thanks!

+3
source share
1 answer
keys = ["number", "url", "title"]
table = [zip(keys, tup) for tup in lines if len(tup) == 3]

if you want to use it as dictionaries:

table = [dict(zip(keys, tup)) for tup in lines if len(tup) == 3]
0
source

All Articles