Created
January 30, 2014 19:16
-
-
Save kf0jvt/8716623 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
def aggregateIndustry(inArray): | |
returnArray = [{'_id':'31-33','friendly_name':'Manufacturing','count':0}, | |
{'_id':'44-45','friendly_name':'Retail','count':0}, | |
{'_id':'48-49','friendly_name':'Transportation','count':0}] | |
for eachIndustry in inArray: | |
if eachIndustry['_id'] in ['31','32','33']: | |
returnArray[0]['count'] += eachIndustry['count'] | |
continue | |
if eachIndustry['_id'] in ['44','45']: | |
returnArray[1]['count'] += eachIndustry['count'] | |
continue | |
if eachIndustry['_id'] in ['48','49']: | |
returnArray[2]['count'] += eachIndustry['count'] | |
continue | |
try: | |
eachIndustry['friendly_name'] = apiconstants.industry_remap[eachIndustry['_id']] | |
returnArray.append(eachIndustry) | |
except: | |
eachIndustry['friendly_name'] = 'Error' | |
returnArray.append(eachIndustry) | |
returnArray = sorted(returnArray,key=itemgetter('count'),reverse=True) | |
return returnArray |
You'll need to add that to your import
call, naturally.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe try
key=attrgetter('count')
?