Created
September 26, 2012 22:03
-
-
Save josephmisiti/3790910 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
| #!/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