Hacker News new | ask | show | jobs
by BerislavLopac 3058 days ago
The speed could possibly be improved by using map. Also, not related to speed if this is all of the code, but might affect it in a larger programs: you should make sure your file pointers are closed. Something like:

    with open('interesting.txt') as interesting_file:
        interesting = {line.strip() for line in interesting_file}
    with open('data.txt') in data_file:
        total = sum(int(val) for id, val in map(lambda line: line.split('\t'), data_file) if id in interesting)
1 comments

`map` is not going to make it faster. `map` is a loop. Only vectorized code is faster.