python不同长度列表,对应合并

1.说明

lis1 = [{‘OS_bit’: u’64 \u4f4d’,
‘OS_version’: ‘10.0.10240’,
‘OS_name’: u’Microsoft Windows 10 \u4f01\u4e1a\u7248 2015 \u957f\u671f\u670d\u52a1\u65b9\u6848’}]
lis2 = [{‘ip’:‘10.20.122.32’}]
lis3 = [{‘CPU_name’: u’Intel® Core™ i5-4200H CPU @ 2.80GHz’}]
lis4 = [{‘memory_size’: ‘1600MHz’,
‘memory_name’: u’Physical Memory 0’},
{‘memory_size’: ‘1600MHz’,
‘memory_name’: u’Physical Memory 2’}]
lis5 = [{‘GPU_name’: u’NVIDIA GeForce GTX 950M’,
‘GPU_size’: ‘2G’},
{‘GPU_name’: u’Intel® HD Graphics 4600’,
‘GPU_size’: ‘1G’}]
有这五个列表,要求合并成一个列表,并且所有列表的第一元素放在新列表的第一元素,以此类推。

2.代码

# !/usr/bin/env/python
# _*_coding:utf-8_*_
# Data:2019-04-10
# Auther:苏莫
# Link:QQ2388873062
# Address:https://blog.csdn.net/lingluofengzang
# PythonVersion:python2.7

import sys

reload(sys)
sys.setdefaultencoding('utf-8')

lis1 = [{'OS_bit': u'64 \u4f4d', 
		'OS_version': '10.0.10240', 
		'OS_name': u'Microsoft Windows 10 \u4f01\u4e1a\u7248 2015 \u957f\u671f\u670d\u52a1\u65b9\u6848'}]
lis2 = [{'ip':'10.20.122.32'}]
lis3 = [{'CPU_name': u'Intel(R) Core(TM) i5-4200H CPU @ 2.80GHz'}]
lis4 = [{'memory_size': '1600MHz', 
		'memory_name': u'Physical Memory 0'}, 
		{'memory_size': '1600MHz', 
		'memory_name': u'Physical Memory 2'}]
lis5 = [{'GPU_name': u'NVIDIA GeForce GTX 950M', 
		'GPU_size': '2G'}, 
		{'GPU_name': u'Intel(R) HD Graphics 4600', 
		'GPU_size': '1G'}]

is_all = [lis1,lis2,lis3,lis4,lis5]
#l print lis_all

new_lis = []
for j in range(2):
	lis = {}
	for i in range(len(lis_all)):
		try:
			lis = dict(lis, **lis_all[i][j])
		except Exception as e:
			pass
		# else:
	new_lis.append(lis)

print new_lis

3.结果

在这里插入图片描述

你可能感兴趣的:(Python)