Created
May 29, 2015 08:34
-
-
Save mdamien/ef03118464377d33dd0e to your computer and use it in GitHub Desktop.
DIY DictReader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def csv_as_dict(filename, limit=None): | |
with open(filename) as f: | |
reader = csv.reader(f, delimiter=';') | |
header = [k.lower() for k in reader.__next__()] | |
for c,row in enumerate(reader): | |
if limit and c >= limit: | |
break | |
yield {key:row[i] for i,key in enumerate(header)} | |
#now I know about csv.DictReader! Thanks pydanny! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment