Question

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 word generate 'word TAB 1' line

Homework Answers

Answer #1

#!/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

import string
sys.path.append('.')

for line in sys.stdin:
   line = line.strip() #trim spaces from beginning and end

line = line.strip(string.punctuation)

   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

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
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...
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...
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...
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))
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT