I am using an external API for Python (specifically 3.x) to get search results based on certain keywords located in a .txt
file. However, due to a constraint as to how many keywords I can search for in every time interval (assume I need an hourly wait) I run the script, I can only use a portion of the keywords (say 50 keywords). How can I, Pythonically, use only a portion of the keywords in every iteration?
Let's assume I have the following list of keywords in the .txt
file myWords.txt
:
Lorem #0
ipsum #1
dolor #2
sit #3
amet #4
...
vitae #167
I want to use on the keywords found in 0-49 (i.e. the first 50 lines) on the first iteration, 50-99 on the second, 100-149 on the third, and 150-167 on the fourth and last iteration.
This is, of course, possible by reading the whole file, read an iteration counter saved elsewhere, and then choose the keyword range residing in that iterable part of the complete list. However, in what I'd like to do, I do not want to have an external counter, but rather only have my Python script and the myWords.txt
where the counter is dealt with in the Python code itself.
I want to take only the keywords that I should be taking in the current run of the script (depending on the (total number of keywords)/50
). At the same time, if I were to add any new keywords at the end of the myWords.txt
, it should adjust the iterations accordingly, and if needed, add new iterations.