Question: # 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
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
