Question

Modify your mapper to count the number of occurrences of each character (including punctuation marks) in...

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

Homework Answers

Answer #1

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]))    

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I need to,  Modify my mapper to count the number of occurrences of each character (including punctuation...
I need to,  Modify my mapper to count the number of occurrences of each character (including punctuation marks) in the file. Code below: #!/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...
Modify your mapper to count words after removing punctuation marks during mapping. Mapper code below. #!/usr/bin/env...
Modify your mapper to count words after removing punctuation marks during mapping. Mapper code below. #!/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...
Update your mapper to count the number of occurrences of each characters in the file. Mapper...
Update your mapper to count the number of occurrences of each characters in the file. Mapper code below: #!/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...
Update your mapper to remove punctuation marks during mapping. mapper code below #!/usr/bin/env python #the above...
Update your mapper to remove punctuation marks during mapping. mapper code below #!/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 # 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...
I need to. Modify my mapper to count words after removing punctuation marks during mapping. mapper...
I need to. Modify my mapper to count words after removing punctuation marks during mapping. mapper is below: 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))
python problem: ( use a loop to read each character from the string and insert into...
python problem: ( use a loop to read each character from the string and insert into the stack) 1. The function main a5.py continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run. 2. Your function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT