在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ python2.7 list轉(zhuǎn)成成元組處理方法

python2.7 list轉(zhuǎn)成成元組處理方法

python2.7下
現(xiàn)有列表:
[{'storage1': '0000:05:00.1', 'storage0': '0000:05:00.0', 'data1': '0000:04:00.1', 'control1': '0000:02:00.1', 'control0': '0000:02:00.0', 'data0': '0000:04:00.0'}, {'storage1': '0000:03:00.1', 'storage0': '0000:03:00.0', 'data1': '0000:06:00.1', 'control1': '0000:81:00.1', 'control0': '0000:81:00.0', 'data0': '0000:06:00.0'}, {'storage1': '0000:03:00.1', 'storage0': '0000:03:00.0', 'data1': '0000:06:00.1', 'control1': '0000:81:00.1', 'control0': '0000:81:00.0', 'data0': '0000:06:00.0'}, {'storage1': '0000:04:00.1', 'storage0': '0000:04:00.0', 'data1': '0000:81:00.1', 'control1': '0000:01:00.1', 'control0': '0000:01:00.0', 'data0': '0000:81:00.0'}, {'storage1': '0000:08:00.1', 'storage0': '0000:08:00.0', 'data1': '0000:05:00.1', 'control1': '0000:02:00.1', 'control0': '0000:02:00.0', 'data0': '0000:05:00.0'}]

想要以{"nic_list":[('0000:05:00.1','0000:05:00.1'),('0000:05:00.0','0000:05:00.0')]}....這種結(jié)構(gòu)顯示所有的數(shù)據(jù),請(qǐng)問如何處理呢,謝謝!

回答
編輯回答
好難瘦
l = [{'storage1': '0000:05:00.1', 'storage0': '0000:05:00.0', 'data1': '0000:04:00.1', 'control1': '0000:02:00.1',
      'control0': '0000:02:00.0', 'data0': '0000:04:00.0'},
     {'storage1': '0000:03:00.1', 'storage0': '0000:03:00.0', 'data1': '0000:06:00.1', 'control1': '0000:81:00.1',
      'control0': '0000:81:00.0', 'data0': '0000:06:00.0'},
     {'storage1': '0000:03:00.1', 'storage0': '0000:03:00.0', 'data1': '0000:06:00.1', 'control1': '0000:81:00.1',
      'control0': '0000:81:00.0', 'data0': '0000:06:00.0'},
     {'storage1': '0000:04:00.1', 'storage0': '0000:04:00.0', 'data1': '0000:81:00.1', 'control1': '0000:01:00.1',
      'control0': '0000:01:00.0', 'data0': '0000:81:00.0'},
     {'storage1': '0000:08:00.1', 'storage0': '0000:08:00.0', 'data1': '0000:05:00.1', 'control1': '0000:02:00.1',
      'control0': '0000:02:00.0', 'data0': '0000:05:00.0'}]

d = {'nic_list': []}

all_poi = []

for item in l:
    for k, v in item.items():
        if 'storage' in k:
            all_poi.append(v)

for i, j in zip(all_poi, all_poi):
    a = (i, j)
    d['nic_list'].append(a)

print(d)
運(yùn)行結(jié)果 {'nic_list': [('0000:05:00.1', '0000:05:00.1'), ('0000:05:00.0', '0000:05:00.0'), ('0000:03:00.1', '0000:03:00.1'), ('0000:03:00.0', '0000:03:00.0'), ('0000:03:00.1', '0000:03:00.1'), ('0000:03:00.0', '0000:03:00.0'), ('0000:04:00.1', '0000:04:00.1'), ('0000:04:00.0', '0000:04:00.0'), ('0000:08:00.1', '0000:08:00.1'), ('0000:08:00.0', '0000:08:00.0')]}
2017年1月26日 12:39