: Thank you so much Drost! I guess the whole read line was what was screwing me up. I was wondering if you could explain a few things to me.
l.count('.'), l.count('!'), l.count('?')
: since l is a whole line is count reading every character in the line?
tempwords = l.split(None)
: This creates a list and the None omits the black characters, right?
: words += len(tempwords)
: nonwhite += sum(map(len, tempwords))
: Why is len(tempwords) when assigned to words counting the number of cells, but when it is in map it counts the number of characters in the cell and creates a new list from that? I read about map and I thought that it would just be applying len to tempwords again, like the line above it. I understand what it is doing I just dont understand why it is doing it.
: Thank you for your help, that gave me a much better understanding of how the syntax of python works. I knew how I wanted to do this I just couldn't get the syntax down at all.
Strings have a count method which take a substring as a parameter and returns the number that can be found in the string.
So basically we count how many end-of-sentence mark we can find in the line.
Again strings have the split method which would result in a list that is created through splitting the string on the boundaries which is the parameter this method takes. The speciality is that the None parameter makes the boundaries to be whitespaces (spaces, tabs, etc.) be them any length
"asd fgh jkl".split(' ')
would result in ["asd", "fgh", "jkl"]
"asd fgh jkl".split(' ') # mark the plus space
would result in ["asd", "fgh", "", "jkl"]
So to get only real words I used .split(None). :)
tempwords is a list which have elements that are the words of the actual line. map iterates on each member of the list (the words) to have their length which would result in a new list of numbers. Their sum makes up how many 'useful' characters there are in the line.
The manual is a great help. :)