I am new with the python, I am trying to get the first letter of every lines from the text file in Mrjob , below is my code:
def mapper(self, key, value):
numCharacters = len(value.strip().replace(" ",""))
numWords = len(value.strip().split())
for word in value.strip().split():
yield value[0],(numCharacters,numWords)
the text.txt file is :
I want to Remove all white spaces.
new lines and tabs.
not the whitespace.
When i execute : python text.py text.txt , the return of the first letter is the whitespace, not the first letter
" " 4.0
" " 4.0
" " 4.0
" " 4.0
" " 4.0
" " 4.0
" " 4.0
" " 4.0
" " 4.0
" " 4.0
" " 4.0
" " 5.67
" " 5.67
" " 5.67
This support to be :
"I" 4.0
"I" 4.0
"I" 4.0
"I" 4.0
"I" 4.0
"I" 4.0
"I" 4.0
"n" 4.0
"n" 4.0
"n" 4.0
"n" 4.0
"n" 5.67
"n" 5.67
"n" 5.67
What is wrong with my code ? please help me to shed the light . Thanks