Kelvin Davis Kelvin Davis - 5 months ago 33
Python Question

Passing a dictionary or its keys as values to a fucntion

So I wrote a function that reads in a .csv file and creates a dictionary of abbreviations and there meaning. Now I'm looking to create a main function that calls the create dictionary function and then prompts the user for keys, but i'm not sure how to access the created dictionary.

import csv

def CreateDictionary(fileName):

with open(fileName, 'r') as f:
reader = csv.reader(f)
newDict = {}
for x, y in reader:
newDict.setdefault(x, []).append(y)
return newDict

def main():
key = input("Please enter a text abbreviation")
for key, value in newDict:


You need to assign the return value of the CreateDictionary function to some variable like this:


this way you can access the items in the dictionary like this: