Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def read _ file ( file ) : d 1 = { } with open ( file , ' r ' , encoding = 'utf
def readfilefile: d with openfilerencoding'utf as infile: lines infile.readlines for index in range lenlines: if linesindexstrip: continue cnt intlinesindexstrip shw linesindex strip if cnt in dkeys: shlist dgetcnt shlist.appendshw else: dcntshw return d def outkeyd filename: with openfilenamew as q: for key in sorteddkeys: qwrite: formatkey; joindgetkey print: formatkey; joindgetkey def outtitled filename: ttl for title in dvalues: ttlextendtitle with openfilenamew as outfile: for title in sortedttl: outfile.write formattitle printtitle def mainx: fname x d readfilefname if d is None: printError: Entered file does not exist!: formatfname return outfile 'outputkeys.txt outfile 'outputtitles.txt outkeyd outfile outtitled outfile printEntere input file name: userinput input mainuserinput
def readfilefile:
d
with openfilerencoding'utf as infile:
lines infile.readlines
for index in range lenlines:
if linesindexstrip:
continue
cnt intlinesindexstrip
shw linesindex strip
if cnt in dkeys:
shlist dgetcnt
shlist.appendshw
else:
dcntshw
return d
def outkeyd filename:
with openfilenamew as q:
for key in sorteddkeys:
qwrite:
formatkey; joindgetkey
print: formatkey; joindgetkey
def outtitled filename:
ttl
for title in dvalues:
ttlextendtitle
with openfilenamew as outfile:
for title in sortedttl:
outfile.write
formattitle
printtitle
def mainx:
fname x
d readfilefname
if d is None:
printError: Entered file does not exist!: formatfname
return
outfile 'outputkeys.txt
outfile 'outputtitles.txt
outkeyd outfile
outtitled outfile
printEntere input file name:
userinput input
mainuserinput
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started