Question: PYTHON. Please complete PART 2 only. Code for part 1 provided below if needed to complete part 2, after instructions for part 1 def main

PYTHON. Please complete PART 2 only. Code for part 1 provided below if needed to complete part 2, after instructions for part 1

def main(): try: d = {} with open('Kennedy.txt', 'r') as f: i = 0 for line in f: i += 1 words = line.strip().split() for word in words: if word not in d: d[word] = [] if i not in d[word]: d[word].append(i) with open('index.txt', 'w') as f: for key, value in d.items(): f.write(key + ': ' + ' '.join([str(x) for x in value]) + ' ') except: print('Kennedy.txt is not found') main()

HERE IS THE TEXT FILE
![for word in words: if word not in d: d[word] = []](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66ef438988134_42566ef43893bb6f.jpg)
PYTHON PROGRAM
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
