File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 24
24
# Shannon's Rules of variable names
25
25
# ---------------------------------
26
26
# 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
28
28
# Use underscores to break up words!
29
29
30
30
# We've stored values inside of lesson_section and lesson_subsection, so now let's use them!
Original file line number Diff line number Diff line change
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' )
You can’t perform that action at this time.
0 commit comments