[Tutor] How to parse large files

jarod_v6 at libero.it jarod_v6 at libero.it
Tue Oct 27 17:32:51 EDT 2015


Hi!
I want to reads two files and create simple  dictionary.  Input file contain more than 10000 rows


diz5 = {}
with open("tmp1.txt") as p:
    for i in p:
        lines = i.rstrip("\n").split("\t")
        diz5.setdefault(lines[0],set()).add(lines[1])

diz3 = {}
with open("tmp2.txt") as p:
    for i in p:
        lines = i.rstrip("\n").split("\t")
        diz3.setdefault(lines[0],set()).add(lines[1])

how can manage better this reading and writing?
thanks so much



More information about the Tutor mailing list