Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# create two dictionaries to store the rows from the input file dict 1 , dict 2 = { } , { } # variable
# create two dictionaries to store the rows from the input file
dict dict
# variable to keep track of the record number
n
# input the CSV file's name to be parsed
filename input
# open the file in read mode
inFile openfilenamer
# read each record from the file using the reader function of the csv module
for record in csvreaderinFile:
# loop through each pair of tokens in the current record
for i in range lenrecord:
# if it is the first record
if n :
# save the current and the next token as keyvalue pairs in dict
dictrecordistrip recordi strip
# otherwise, it is the second record
elif n :
# save the current and the next token as keyvalue pairs in dict
dictrecordistrip recordi strip
# increment the record number
n
# close the input file
inFile.close
# print both the dictionaries
printDictdict
printDictdict
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