我有两组具有相似数据的列表,我需要将它们组合成字典。该列表必须包含两组信息,在对方有“-”的地方填写。到目前为止,这就是我所拥有的..
aList = [['Last Name', 'First Name', '2000', '2012'],
['Roberts', 'Gloria', '-', '123000'],
['Arreguin', 'Jeffrey', '81000', '-'],
['Myers', 'George', '-', '86000'],
['Willis', 'Mabel', '112000', '-'],
['Oneal', 'Kevin', '96000', '77000'],
['Paz', 'Barbara', '-', '77000'],
['Franklin', 'Claude', '94000', '-'],
['Bradley', 'Shannon', '89000', '-'],
['Fix', 'Anna', '76000', '126000'],
['Meyer', 'Loretta', '-', '116000'],
['Daniels', 'Christina', '85000', '-'],
['Graham', 'Veronica', '-', '136000']]
newList = [['Last Name', 'First Name', '2000', '2012'],
['Meyer', 'Loretta', '123000', '-'],
['Arreguin', 'Jeffrey', '81000', '-'],
['Mielke', 'George', '137000', '-'],
['Thomas', 'Lewis', '132000', '-'],
['Harper', 'Crystal', '80000', '-'],
['Young', 'Gary', '-', '94000'],
['Franklin', 'Claude', '94000', '-'],
['Hedrick', 'James', '-', '105000'],
['Bradley', 'Shannon', '89000', '-'],
['Thigpen', 'Michael', '79000', '-'],
['Willis', 'Mabel', '112000', '-'],
['Hullinger', 'Molly', '70000', '-'],
['Myers', 'George', '-', '86000'],
['Paz', 'Barbara', '-', '77000'],
['Edwards', 'Kathryn', '117000', '97000'],
['Roberts', 'Gloria', '-', '123000'],
['Daniels', 'Christina', '-', '137000'],
['Graham', 'Veronica', '-', '136000']]
def mergeData(newList,aList):
aDict={}
for item in range(1,len(newList)):
key=(newList[item][0],newList[item][1])
value=(newList[item][2],newList[item][3])
aDict[key]=value
for item in range(1,len(aList)):
#stuck here not sure if im going right way with this
print(aDict)
这是一个示例
newList= ['Meyer', 'Loretta', '123000', '-']
aList=['Meyer', 'Loretta', '-', '116000']
所以组合字典应该是
{(‘Meyer’, ‘Loretta’): (‘123000’,’116000’)}
对于这个条目。