Reputation: 3893
I'm reading Mark Pilgrim's Dive into Python 3 and have been staring at this for about an hour now: http://getpython3.com/diveintopython3/strings.html#common-string-methods
>>> s = '''Finished files are the re-
... sult of years of scientif-
... ic study combined with the
... experience of years.'''
>>> s.lower().count('f')
6
In the multi-line string example given, I don't understand why s.lower().count('f')
returns 6 instead of 3. I have confirmed that it does return 6. Of course, Pilgrim even points out in his notes that it is in fact 6, but doesn't explain why.
Can someone help me out? Thanks!
Upvotes: 1
Views: 676
Reputation: 78590
There are 6 f's in that statement. You might be accidentally ignoring the "of"s.
(Indeed, this is a widely circulated brainteaser).
Upvotes: 5
Reputation: 6647
Finished files are the result of years of scientific study combined with the experience of years.
The 'lower' makes it so the entire string is lowercase, so make sure to include things like "Finished".
Upvotes: 2