我需要从sqlite3
拆分此列表 [(107, u'Ella', u'Fitzgerald'), (108, u'Louis', u'Armstrong'), (109, u'Miles', u'Davis'), (110, u'Benny', u'Goodman')]
进入
107, 'Ella', 'Fitzgerald'
108, 'Louis', 'Armstrong'
109, 'Miles', 'Davis'
110, 'Benny', 'Goodman'
如何获得这个?
感谢。
答案 0 :(得分:2)
尝试以下方法:
data = [(107, u'Ella', u'Fitzgerald'), (108, u'Louis', u'Armstrong'), (109, u'Miles', u'Davis'), (110, u'Benny', u'Goodman')]
for record in data:
print '{0:}, {1:}, {2:}'.format(*record)
# or in case you want to get a dictionary
d = dict([(x[0], ', '.join(x[1:])) for x in a])# sure that you can skip merging name and surname here(just replace join with x[1:])
for k, v in d.iteritems():
print '%s, %s' % (k, v)
>>>107 Ella, Fitzgerald
>>>108 Louis, Armstrong
>>>109 Miles, Davis
>>>110 Benny, Goodman
答案 1 :(得分:0)
这样您就可以将元组分成3个不同的变量:
for tuples in sqlite_list:
id, name, last_name = tuples
.... #Do what you need