Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (Retired) Tuples Tuples With Functions

Small questions: why key.title() instead of just key? And why no ** example?

Hi!

In the last example, Kenneth Love used key.title() in the .format() call instead of just key, even though (I believe) the latter would work just as well. I'm sure he had a reason for this; just wondering what it is.

Also, found it kind of strange that he prepped us to be able to use a ** when looping over a dictionary's items, but did not use it in any example. What was the reason for this / where can an example of such be found in this course?

Thanks! and Be Well, Graham

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are correct that key could have been used. The value of key, at this point, is a string holding the dictionary key. Since this string is of type str, the method .title() is available. From help(str.title):

title(...) method of builtins.str instance
    S.title() -> str

    Return a titlecased version of S, i.e. words start with title case
    characters, all remaining cased characters have lower case.

Thanks for this, Chris. I did not realize that .title() was a case! I assumed it was just the 'title' of the key, ha.

Dave Huckle
Dave Huckle
7,030 Points

Haha, I thought the same.