Write a function named "csv_to_kvs" that takes a string as a parameter representing the name of a CSV file with 4 columns in the format "string, float, float, float" and returns a new key-value store mapping strings to floating point numbers. The returned key-value store will have one pair for each row in the file with keys from the first column of the CSV file and values from the third column. (My code below)
import csv
def csv_to_kvs(string):
with open(string) as f:
file = csv.DictReader(f)
for column in file:
for key in column.keys():
return key
for value in column.values():
return value
When I submit the following function csv_to_kvs, I get an incorrect input.
input experienced.csv:
spite,-11.09,3.92,7.38
questionnaire,12.8,-4.39,-0.14
literally,19.5,-3.94,-5.06
colleague,17.19,-15.3,0.12
returned: "spite"
expected: {'colleague': -15.3, 'spite': 3.92, 'questionnaire': -4.39, 'literally': -3.94}
csv_to_kvs, with what file contents, you get what? (BTW, did you mean "incorrect output" or "error about incorrect input"? Whichever it is, attach it as well.)returnstatement. your code will return value for first iteration.