Skip to content

Instantly share code, notes, and snippets.

@lbragstad
Last active September 7, 2018 14:25
Show Gist options
  • Save lbragstad/a812df72494ffbbbc8c742f4d90333d5 to your computer and use it in GitHub Desktop.
Save lbragstad/a812df72494ffbbbc8c742f4d90333d5 to your computer and use it in GitHub Desktop.
User Survey Parser
#!/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