1

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!

1
  • 2
    Four answers? And 12 total upvotes? (so far). For counting f's? Commented May 4, 2012 at 18:35

4 Answers 4

5

There are 6 f's in that statement. You might be accidentally ignoring the "of"s.

(Indeed, this is a widely circulated brainteaser).

Sign up to request clarification or add additional context in comments.

3 Comments

I mean, normally I would admit to just being an idiot, but Pilgrim's comment makes it seem like many would not count the "of"s...
The "f" in "of" sounds like "v" so if you file words mentally by their sound (as many do), you will miss them.
Don't feel too bad, @JeffErickson, even knowing the answer it took me 3 read-throughs to find the 6th one.
5

Finished... files... of... of... scientific... of...

Comments

4

This might be a helpful visual.

Six f's

Comments

2

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".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.