Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
55 lines (36 loc) · 1.55 KB

File metadata and controls

55 lines (36 loc) · 1.55 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Perform an Excel VLOOKUP with a Python Dictionary
# Challenge 3
# Create a function that takes a filepath as a parameter and returns the sum of donations
import csv
import os
from pprint import pprint
current_directory = os.getcwd()
pycon_sponsors_filename = 'pycon_sponsors.csv'
pycon_sponsors_filepath = os.path.join(current_directory, "data", pycon_sponsors_filename)
print(pycon_sponsors_filepath)
def sum_donations(filepath):
sponsor_levels = [{'sponsor_level': 'VISIONARY', 'amount': 150000},
{'sponsor_level': 'SUSTAINABILITY', 'amount': 90000},
{'sponsor_level': 'MAINTAINING', 'amount': 60000},
{'sponsor_level': 'CONTRIBUTING', 'amount': 30000},
{'sponsor_level': 'SUPPORTING', 'amount': 15000},
{'sponsor_level': 'PARTNER', 'amount': 7500},
{'sponsor_level': 'PARTICIPATING', 'amount': 3750},
{'sponsor_level': 'ASSOCIATE', 'amount': 1500}]
sponsor_vlookup = {}
for sponsor_level in sponsor_levels:
sponsor_vlookup[sponsor_level['sponsor_level']] = sponsor_level['amount']
pycon_sum = []
with open(filepath, 'r') as f:
rows = csv.reader(f)
header = next(f)
for row_number, row in enumerate(rows):
ticker, name, level = row
value = int(sponsor_vlookup[row[2]])
pycon_sum.append(value)
return pycon_sum
"""
Output:
pycon_sum = sum_donation(pycon_sponsors_filepath)
print("Total Donation:\t", pycon_sum)
"""
Morty Proxy This is a proxified and sanitized view of the page, visit original site.