Last active
April 12, 2017 14:43
-
-
Save galarant/e056469e7dc4f7f65098d07f21a42358 to your computer and use it in GitHub Desktop.
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
businesses = [] | |
inspections = [] | |
for row in reader(): | |
# Find business in my list if it exists, else default to None | |
# The technique is not obvious or simple, but see here for explanation: | |
# http://stackoverflow.com/a/8653568/765103 | |
camis = row[0] | |
business = next((b for b in businesses if b.camis == camis), None) | |
# If business was not in the list, then create it and add it to my list | |
if not business: | |
business = Business(camis=camis, name=row[1], ...) | |
businesses.append(business) | |
# So the above functions basically like a get or create for our list | |
# But in either case we now have a valid business so we can do the inspection | |
inspection = Inspection(business=business, date=foo, grade=bar, ...) | |
inspections.append(inspection) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment