Skip to content

Commit 4855bf1

Browse files
committed
Added csv to dict.py (lesson 4) and fixed typo in lesson 1 comments
1 parent f2aa80c commit 4855bf1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

section_01_(basics)/variable_assignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Shannon's Rules of variable names
2525
# ---------------------------------
2626
# Variables should be descriptive, even if it means their names are long
27-
# You should be able to show your code to anyone and they'll know exactly information what a given variable holds
27+
# You should be able to show your code to anyone and they'll know exactly what information a given variable holds
2828
# Use underscores to break up words!
2929

3030
# We've stored values inside of lesson_section and lesson_subsection, so now let's use them!

section_09_(functions)/csv_to_dict.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
def csvtodict(filename):
3+
4+
with open(filename, 'r') as csv_file:
5+
text = csv_file.read().strip().split('\n')
6+
7+
header_row = text[0].split(',')
8+
9+
dictionary = {}
10+
11+
for row, line in enumerate(text[1:]):
12+
13+
dictionary[row] = {}
14+
15+
for col, cell in enumerate(line.split(',')):
16+
17+
dictionary[row][header_row[col]] = cell
18+
19+
20+
return dictionary
21+
22+
23+
print csvtodict('events.csv')

0 commit comments

Comments
 (0)