Skip to content

Instantly share code, notes, and snippets.

@fkchang
Created August 14, 2019 21:23
Show Gist options
  • Save fkchang/3c51edd5ffd2b82eae006ce0eabc4f2e to your computer and use it in GitHub Desktop.
Save fkchang/3c51edd5ffd2b82eae006ce0eabc4f2e to your computer and use it in GitHub Desktop.
from collections import defaultdict
str = '''company_name,service
Johns Refuge,Normal Pickup
Johns Refuge,Bulk Pickup
Johns Refuge,Tree Removal
Bobs Limited,Normal Pickup
Bobs Limited,Bulk Pickup
'''
lines = str.split("\n")
data = lines[1:-1]
ddict = defaultdict(list)
for str in data:
company, services = str.split(",")
ddict[company].append(services)
for company, services in ddict.items():
print(company + ',' + '"' + ','.join(services) + '"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment