3

sqlite3 からデータを読み取ると、出力は次のようになります (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)

だから私はそれを次のようなテーブルに再フォーマットしたい: table = [["", "number", "url", "title"], ["number", 3252], ["urls", .....], ["title", ....]] それで、分割はタプルに使用できないため、どうすればこのように作成できますか...ありがとう!!

4

1 に答える 1

0
keys = ["number", "url", "title"]
table = [zip(keys, tup) for tup in lines if len(tup) == 3]

辞書として使用する場合:

table = [dict(zip(keys, tup)) for tup in lines if len(tup) == 3]
于 2012-04-18T14:22:54.703 に答える