admin@kzr-home:~$ cp gibberish.txt{,.bak} admin@kzr-home:~$ for i in {1..5000}; do cat gibberish.txt.bak >> gibberish.txt; done admin@kzr-home:~$ time ./task.py 1. people 2. sound water would water people or many from would than each sound of people who what see number was up at has there the from be is their can at who some was their water day with word have call had I said them with and you 3. 550079 4. 550097 5. 3 real 0m19.991s user 0m19.824s sys 0m0.164s admin@kzr-home:~$ time ./task_fast.py 1. people 2. sound water would water people or many from would than each sound of people who what see number was up at has there the from be is their can at who some was their water day with word have call had I said them with and you 3. 28 4. 97 5. 3 real 0m14.403s user 0m13.952s sys 0m0.448s