Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3 4 . 1 3 PRACTICE: Manipulate CSV files Instructions: Create a Python solution to the following task. Ensure that the solution produces output in
PRACTICE: Manipulate CSV files
Instructions:
Create a Python solution to the following task. Ensure that the solution produces output in exactly the same format shown in the samples below, including capitalization and whitespace.
Task:
Create a solution that accepts an input identifying the name of a CSV file, for example, "inputcsv Each file contains two rows of commaseparated values. Import the builtin module csv and use its open function and reader method to create a dictionary of key:value pairs for each row of commaseparated values in the specified file. Output the file contents as two dictionaries.
The solution output should be in the format
key: 'value', 'key': 'value', 'key': 'value'
key: 'value', 'key': 'value', 'key': 'value'
Sample InputOutput:
If the input is
inputcsv
then the expected output is
a: b: c:
bananas: 'steak': 'cookies':
Alternatively, if the input is
inputcsv
then the expected output is
d: e: f:
celery: 'milk': 'bread':
#import csv module and call open reader
import csv
# dict
# dict
filename input
with openfilenamer as file:
#solution accepts input identifying name of CSV file ie "inputcsv
data csvreaderfile
#solution outputs each row of CSV file contents as a dictionary of elements
for row in data:
for word in row:
dict:joinrow
# dict row
printdict
# printdict
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