Question: Please, I need to complete my code with this: Use ThreadPoolExecutor to spawn two threads, each of which loads one of the name text files
Please, I need to complete my code with this:
-
Use ThreadPoolExecutor to spawn two threads, each of which loads one of the name text files and returns the name list.
-
This will require a worker/future function that accepts a filename as a parameter and returns the processed list of names
-
import random
last_names = [] first_names = []
def generate_people(count): with open('LastNames.txt', 'r') as filehandle: last_names = [line.rstrip() for line in filehandle] with open('FirstNames.txt', 'r') as filehandle: first_names = [line.rstrip() for line in filehandle]
names = list()
for i in range(count): names.append((i, first_names[random.randint(0, len(first_names)-1)], last_names[random.randint(0, len(last_names)-1)])) return names if __name__ == "__main__": people = generate_people(5) print(people)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
