I need some help with a assignment for Python. The task is to make a dictionary with keys from a other dictionary and values from a csv file. All this needs to be done with a function with arguments(The other dictionary, the_csv_file)
The other dictionary looks like this:
{1: 'Bob West', 2: 'Hannah North', 3: 'Bruce South', 4: 'Anna
Bell', 5: 'George Smith'}
And i got that dictionary from a function
def names_dictionary():
with open("filename.csv", 'r') as d:
x = {num+1:name.split(" ",1)[-1].strip() for (num, name)
in enumerate(d)}
print(x)
From this dictionary i need the values(the names) to be keys in the new dictionary.
The CSV file looks like this in excel
A B
1.1 11
2.3 12
3.2 14
4.7 11
5.5 12
Everything in column A.
From here i want the second number in every row to be the value in the new dictionary. So (11, 12, 14, 11, 12).
The result dictionary I want is
{’Bob West’: 11, ’Hannah North’: 12, ’Bruce South’: 14, ’Anna
Bell’: 11, ’George Smith’: 12}
The function so far.
def names(names_dictionary, csvfile):
And for the end i need a main function who puts together and output:
Bob West got 11 bananas Hannah North got 12 bananas Bruce South got 14 bananas Anna bell got 11 bananas George Smith got 12 bananas