Skip to content

Instantly share code, notes, and snippets.

@ifournight
Created February 26, 2015 16:01
Show Gist options
  • Save ifournight/bf580952f6a4527c9e3d to your computer and use it in GitHub Desktop.
Save ifournight/bf580952f6a4527c9e3d to your computer and use it in GitHub Desktop.
py
import csv
# Map row to dictionary (dictionary comprehension)
def player(column_names, row):
return {column_names[column]: data for column, data in enumerate(row) if column < len(column_names)}
# Map CSV file to list of dictionaries (list comprehension)
players = [player(['name', 'position', 'game_info', 'price'], row) for row in csv.reader(open('dk.csv', 'r'))]
def loadAvatarCsv(row):
return {'avatar_id': row[0], 'avatarsuit_id': row[2]}
avatar_csv = [loadAvatarCsv(row) for row in csv.reader(open('Avatar.csv', 'r'))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment