Hacker News new | past | comments | ask | show | jobs | submit login

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)



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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: