I wrote this code:
logFile = sc.textFile("\README.md") #read the file
def lengthfunction(line):
return len(line)
logFile.map(lambda line: line.split()).reduce(lengthfunction)
It gave me an error:
"lengthfunction() takes exactly 1 argument (2 given)"
I also tried
logFile.map(lambda line: line.split()).reduce(lambda line: len)
But that did not work too. Can someone help me out?
您可以:
logFile.map(lambda line: line.split()).map(len)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.