I have this problem. I have two files .txt, match_list
of this form:
Sevilla, Ath Bilbao
Valencia, Valladolid
Getafe, Atl. Madrid
and data
Getafe, Atl. Madrid,5:00 PM, Coliseum Alfonso Pérez, 9.500,27.8, 2.760.000,8
Valencia, Real Valladolid,7:00 PM, Mestalla, 41.000,26.3, 8.640.000,6
Sevilla, Ath Bilbao,8:00 PM, Ramón Sánchez Pizjuan, 4-2-3-1,26, 5.488.000,11
I want to loop through both files, match team names and copy all the data corresponding to each match from data.txt
to match_list.txt
.
My code couldn't handle this (maybe because i'm looping only through one file?):
match_data = open('data.txt').readlines()
match_list = open('m_list.txt').readlines()
outfile = open('done.txt', 'w')
for line in match_data:
if line[:2] == match_list[:2]:
match_list = match_list+',' + line[2:]
outfile.write(match_list)