[{'name1':'Jack'},{'name2':'Lara'}]------>得到[name1, name2]
for循环嵌套,列表生成式写法:
alist=[{'name1':'Jack'},{'name2':'Lara'}] b = [j for one in alist for j in one] print(b)
for循环嵌套,普通写法:
alist=[{'name1':'Jack'},{'name2':'Lara'}] blist=[] for one in alist: for k,v in one.items(): blist.append(k) print(blist)
[{'a':'1','b':'11'},{'a':'2','b':'21'},{'a':'3','b':'31'}]------>得到['1', '2', '3']
b = [one.pop('a') for one in alist] print(b)