I want to find number of lines and words in a file. My input file "testfile.txt' has 6 lines and 23 words. For finding number of words I am using map() function instead of the for loop. When I executed this code it shows the memory location of the object instead of "23": Number of words =
What am I doing wrong here?
def wordcount(l):
global numwords
words = l.split()
numwords += len(words)
f=open('testfile.txt')
lines = f.readlines()
numlines = len(lines)
print ('Number of lines =', numlines)
numwords=0
numwords = map(wordcount, lines)
print ('Number of words =', numwords)