Question: PART 2 : Write additional code Update the above code to add the following functionality: 2 a . For each line in lab 3 in
PART : Write additional code
Update the above code to add the following functionality:
a For each line in labintxt create list of words and print the list. This list may contain duplicates. For
this program, words are groups of characters separated by one or more spaces.
b Add the words in the line to a set called words. NOTE: A set is an unordered collection with no duplicate elements. The words are casesensitive so for example, 'The' and 'the' will be considered two separate words.
COMP : Programming for Beginners II
FALL LAB #
c For each line you should also print the contents of the line in uppercase in an output file called labout.txt
d After all the lines have been processed, write the final value of words in the output file.
Sample output output file: NOTE: screenshot does not show full set of words
# PART ONE
#import file
infile openlabintxtr
nume #default #
numlines #default #
#function
for line in infile:
numlines numlines
line line.rstrip
counte line.counte
nume nume counte
# print statement for e in line
printfline line # of es counte # Output format
#find avg
avg roundnumenumlines,
#print statement
printaverage # of occurances of e per line avg
infile.close
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
