背景
将两个txt文件通过两者共有的某一项进行关联,类似于数据库中的不同表通过id相关联。
txt1:#checkins(userID/venueID/time/offset)
txt2:#pois(venueID/latitude/longtitude/words/country)
通过共有项venueID,将txt1的数据以及txt2的数据关联起来,写入一个新的文件txt3。
格式如userID/venueID/time/offset/latitude/longitude/words/country
思路
将txt2文件的venueID作为字典的key,然后将latitude,longtitude,words,country写入一个列表里作为字典的值。
比对txt1中的venueID,相同则直接将txt1的此行写入txt3,同时将字典中的venueID对应的值——latitude,longtitude,words,country写入txt3
代码
f1=open('f:\checkins.txt','r') |