# deal with headings separately from rest of data.
# also split each heading into a list of string rather than single string.
l1_headings, l2_headings = List_1.pop(0).split(), List_2.pop(0).split()
# put each row of List_1 in a list of dictionary using headings as keys
l1_dicts = [{k:v for k, v in zip(l1_headings, row.split())} for row in List_1 if row != '']
# put each row of List_2 in a dictionary of dictionaries indexed by 'Sta'
l2_by_Sta = {}
for row in List_2:
if row == '': continue
d = {k:v for k, v in zip(l2_headings, row.split())}
l2_by_Sta[d['Sta']] = d
# update l1_dicts from data in l2_by_Sta
for d in l1_dicts:
d.update(l2_by_Sta[d['Sta']])
l1_dicts
이제 포함
[{'Azimuth': '170.7011111',
'Departure': '-3.593',
'Distance': '22.236',
'Easting': '2000',
'Latitude': '21.9438',
'Northing': '2000',
'Pno': 'X',
'Sta': 'T1'},
{'Azimuth': '170.0',
'Departure': '-3.473',
'Distance': '20.0',
'Easting': '2000',
'Latitude': '19.6962',
'Northing': '2000',
'Pno': 'X',
'Sta': 'T1'},
{'Azimuth': '30.22833333',
'Departure': '-3.0625',
'Distance': '6.083',
'Easting': '1600',
'Latitude': '-5.2559',
'Northing': '1500',
'Pno': 'X',
'Sta': 'T2'},
{'Azimuth': '154.5155556',
'Departure': '-42.2573',
'Distance': '98.212',
'Easting': '2200',
'Latitude': '88.6562',
'Northing': '2400',
'Pno': 'X',
'Sta': 'T3'},
{'Azimuth': '351.4977778',
'Departure': '13.844',
'Distance': '93.637',
'Easting': '2800',
'Latitude': '-92.6079',
'Northing': '2600',
'Pno': 'CHB',
'Sta': 'T4'}]
텍스트 파일 사용 csv.DictWriter
이 데이터를 작성해야합니다.
스택 오버플로에 대한 질문을하는 방법에 대한 섹션을 살펴보아야합니다. –
시도해 보았던 것을 보여주고 계속 붙잡은 것에 대해 자세히 설명해주십시오. 그래서 사람들이 코드를 작성하도록 웹 사이트가 아닙니다. – Antimony
[도움말 센터] (http://stackoverflow.com/help)의 [좋은 질문이 있습니까?] (http://stackoverflow.com/help/how-to-ask)를 참조하십시오. –