Modify your mapper to count the number of occurrences of each character (including punctuation marks) in the file.
#!/usr/bin/env python
#the above just indicates to use python to intepret this file
#This mapper code will input a line of text and output <word, 1> #
import sys
sys.path.append('.')
for line in sys.stdin:
line = line.strip() #trim spaces from beginning and end
keys = line.split() #split line by space
for key in keys:
value = 1
print ("%s\t%d" % (key,value)) #for each word generate 'word TAB 1' line
If you have any doubts, please give me comment...
#!/usr/bin/env python
inp_fname = input("Enter input filename: ")
fp = open(inp_fname)
occurances = {}
for line in fp.readlines():
line = line.strip() #trim spaces from beginning and end
for ch in line:
if ch not in occurances:
occurances[ch] = 0
occurances[ch] += 1
fp.close()
print("Char\tCount")
for ch in occurances:
print(ch+"\t"+str(occurances[ch]))
Get Answers For Free
Most questions answered within 1 hours.