Answered step by step
Verified Expert Solution
Link Copied!

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

34.13 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 sample(s) below, including capitalization and whitespace.
________________________________________
Task:
Create a solution that accepts an input identifying the name of a CSV file, for example, "input1.csv". Each file contains two rows of comma-separated values. Import the built-in module csv and use its open() function and reader() method to create a dictionary of key:value pairs for each row of comma-separated 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 Input/Output:
If the input is
input1.csv
then the expected output is
{'a': '100','b': '200','c': '300'}
{'bananas': '1.85', 'steak': '19.99', 'cookies': '4.52'}
Alternatively, if the input is
input2.csv
then the expected output is
{'d': '400','e': '500','f': '600'}
{'celery': '2.81', 'milk': '4.34', 'bread': '5.63'}
#import csv module and call open(), reader()
import csv
# dict1={}
# dict2={}
filename = input()
with open(filename,"r") as file:
#solution accepts input identifying name of CSV file (i.e., "input1.csv")
data = csv.reader(file)
#solution outputs each row of CSV file contents as a dictionary of elements
for row in data:
for word in row:
dict1=":".join(row)
# dict2= row[1]
print(dict1)
# print(dict2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

What are some of the hiring standards to avoid?

Answered: 1 week ago

Question

What are some metrics for evaluating recruitment and selection?

Answered: 1 week ago