Code wars : Title Case with python
<pre><code>def title_case(title, minor_words = 0):
    title = title.lower().split(" ")
    title_change = []
    temp = []
    if minor_words != 0 :
        minor_words = minor_words.lower().split(" ")
        for i in range(len(title)):
            if (i != 0 and title[i] not in minor_words) or (i == 0 and title[i] in minor_words):
                temp = list(title[i].lower())
                temp[0] = temp[0].upper()
                title_change.append("".join(temp))
            else:
                title_change.append(title[i])
            temp = []
    else:
        for i in range(len(title)):
            temp = list(title[i])
            temp[0] = temp[0].upper()
            title_change.append("".join(temp))
            temp = []
    return " ".join(title_change)
</code></pre>

<p>Hello,this is my python code here.
This is the question:
A string is considered to be in title case if each word in the string is either (a) capitalised (that is, only the first letter of the word is in upper case) or (b) considered to be an exception and put entirely into lower case unless it is the first word, which is always capitalised.</p>

<p>Write a function that will convert a string into title case, given an optional list of exceptions (minor words). The list of minor words will be given as a string with each word separated by a space. Your function should ignore the case of the minor words string -- it should behave in the same way even if the case of the minor word string is changed.</p>

<p>I am trying not to use capitalize() to do this.It seems my code works fine on my computer,but the code wars just prompted "IndexError: list index out of range".</p>

<p>Just as a supplement to @Blckknght's explanation, here is an illuminating console session that steps through what's happening to your variable.</p>

<pre><code>&gt;&gt;&gt; title = ''
&gt;&gt;&gt; title = title.lower().split(' ')
&gt;&gt;&gt; title
['']
&gt;&gt;&gt; temp = list(title[0])
&gt;&gt;&gt; temp
[]
&gt;&gt;&gt; temp[0]
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
IndexError: list index out of range
</code></pre>

<p>I tried your solution on other (non-whitespace) inputs, and it works fine.</p>

python indexing