performance - *SOLVED* Is there any way to improve the speed of reading a text file in Python? -
i reading file of 587 kb contains words a-z like: aa bb cc ...and on... now, no matter code write, literally takes 38 seconds read file!
with open('dictionary.txt', encoding = 'utf-8') dictionary: dictionary.read().splitlines()
my question is: how can read file in less @ least 4 seconds? also, must return words in list.
the problem has been solved "all right, everyone. got it! instead of being in problem , selecting random word, printing words instead, silly me. , when doing this, it's giving me word in fraction of second: pastie.org/8149529 "
this should require less memory because iterates on lines:
words = [] open('dictionary.txt', encoding='utf-8') dictionary: line in dictionary: words.extend(line.split())
Comments
Post a Comment