Last active
September 7, 2018 14:25
-
-
Save lbragstad/a812df72494ffbbbc8c742f4d90333d5 to your computer and use it in GitHub Desktop.
User Survey Parser
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
#!/usr/bin/env python3 | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
'filename', | |
help=('User survey results as a file with each line being a list of ' | |
'responses per user.') | |
) | |
args = parser.parse_args() | |
results = dict() | |
with open(args.filename, 'r') as f: | |
for line in f.readlines(): | |
segments = line.split('|') | |
for part in segments: | |
part = part.rstrip() | |
if part in results: | |
results[part] += 1 | |
else: | |
results[part] = 1 | |
for k, v in sorted(results.iteritems(), key=lambda (k, v): (v, k), reverse=True): | |
print('%s had %d responses' % (k, v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment