Here is the relevant code I have. It is using a generator to get the words from the file. However, the words are first stored into a variable before entering a function. Is this correct?
Does this take advantage of the generator functionality?
def do_something(words):
new_list = {}
for word in words:
// do stuff to each word
// then add to new_list
return new_list
def generate_words(input_file):
for line in input_file:
for word in line.split(' '):
// do stuff to word
yield word
if __name__ == '__main__':
with open("in.txt") as input_file:
words = generate_words(input_file)
do_something(words)
Thank you