Skip to content

Instantly share code, notes, and snippets.

@josephmisiti
Created September 26, 2012 22:03
Show Gist options
  • Save josephmisiti/3790910 to your computer and use it in GitHub Desktop.
Save josephmisiti/3790910 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
import sys, os, re, random
def mapper(args):
for line in sys.stdin:
sys.stdout.write(line.strip() + "\n")
def reducer(args):
for line in sys.stdin:
line = line.strip()
sys.stdout.write("\t".join(line.split(",")) + "\n")
if __name__ == "__main__":
if len(sys.argv) == 1:
os.system('cat ratings.csv | ./user_stats.py mapper | LC_ALL=C sort | ./user_stats.py reducer')
elif sys.argv[1] == "mapper":
mapper(sys.argv[2:])
elif sys.argv[1] == "reducer":
reducer(sys.argv[2:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment