Python: Writing on Memory Limit Environment

In this article, we are going to try use limited memory as we force to work on during early 50s. The memory limitation will force the programmer to come up with ways of rotating data through the available memory. Let discuss more on the program.

Practice with Memory limit Style

there-must-be-a-limit-andrew-gower
there-must-be-a-limit-andrew-gower
  1. Create a list of stop_words.txt to identify words.
  2. Create a function to open file and its option – r, rb (read or read binary)
  3. Next, we define a data list array to be used for loading the words from file.
  4. It will also include start index, index, flag, word, words and its memory position, frequency
  5. Read from the command input – file name (input.txt)
limit code1
limit code1
  1. In the main loop, read each line from input file.
  2. Get the value for each row and check if words are founded.
  3. Create word_freqs.txt file to store value word not found in stop words file.
    1. It will store the words and frequency
    2. If this is 1st time the word is found, then save into the file with reoccurrence = 1
    3. If more than 1, reoccurrence set to +=1
limit code2
limit code2
  1. Next, in the 2nd part of the code is to read the top 25 lines of word freq file
    1. Get the reoccurrence number and the word
    2. Print out the values.
limit code3
limit code3

Let try to run the program and see the outcome.

limit program
limit program
word frequency
word frequency

Thanks for reading and enjoy your day.

Leave a comment