Answer the question
In order to leave comments, you need to log in
How from another?
I found it like this: while reading Real World Haskell, I learned about the combinatorial parsing library Parsec. The examples in the book are amazing. Unlike the traditional approach, there is no division into lexical analysis (selection of "words" - lexemes) and syntactic analysis (transformation of a stream of "words" into an ordered data structure) - in combinatorial parsing, these two stages are combined. Small functions are taken that recognize elements of the text, and then they are combined according to the syntax of the text. Thus, the combination of functions itself directly reflects grammar, and it, of course, is also a program for parsing text. Like any good idea, Parsec has many imitations. For Python combinatorial parsers, there were as many as two already three already four - Pysec, Pyparsing, LEPL (for Python 2.6 / 3.0) and funcparselib.
Answer the question
In order to leave comments, you need to log in
1) save the 1st file in CSV format so as not to suffer. I will call it the 1st file
2) Collect the 1st fileset
from the full name. 3) open the 3rd file
for writing
4) Read the 2nd file line by line, parse the line, extract the full name, phone number. If the full name is in set, then save the line full name + phone number in the 3rd file .
Tavk seems to be a fairly simple task. If all full names from the first file fit into memory, for example, in a dict, then:
1) create a dict with a key by full name from the first file and an empty array
2) run through the second file line by line and check the full name by key, if there is a key, then add to phone array.
3) We save all records from dict where the array is not empty.
# stage 1
all_fio = dict()
with open('myfiofile','r') as fp_fio:
for line in fp_fio:
(_f,_i,_o,_,_) = line.split(';')
_fio = _f+' '+_i +' ' + _o
all_fio[_fio] = []
# stage 2
with open('mybilphonelog','r') as fp_log:
for line in fp_log:
(_t1,_t2,_fio,_) = line.split(';')
if all_fio.has_key(_fio):
all_fio[_fio].append(_t1)
all_fio[_fio].append(_t2)
# stage 3
import json
json.dump(all_fio, open('myresultfile','w'))
Is it not an option to drive all this into mysql and get the necessary data with a couple of queries?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question