Last active
August 29, 2015 13:56
-
-
Save keskarnitish/9105195 to your computer and use it in GitHub Desktop.
A simple script to count number of words and lines in a document using only map and reduce functions (No Loops). Usage: cat foobar.txt | python LineWordCounter.py
This file contains 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
# A simple script to count number of words and lines in a document using only map and reduce functions (No Loops) | |
# Usage: cat foobar.txt | python LineWordCounter.py | |
import sys | |
DataToRead = sys.stdin.read() | |
print "Document has " + str(sum(map(lambda x: x=='\n',DataToRead))) + " lines" | |
print "Document has " + str(len(map(len, DataToRead.split()))) + " words" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment