Appending letters to a list in a while loop
<p>I am trying to append the first word of a sentence to an empty list. The current code is below:</p>

<pre><code>sentence = input("Enter sentence: ")

subject = []
print (subject)

x = 0
while True:
    letter = sentence[x]
    if letter != " ":
        print (letter)
        subject.append(letter)
        x = x + 1

print (subject)
</code></pre>

<p>It currently prints this:</p>

<pre><code>Enter sentence: Cherries are red fruit

[]
C
h
e
r
r
i
e
s
</code></pre>

<p>It seems to ignore my attempt to append the result to the empty list... Help, please! </p>

<p>Why not use the <code>split()</code> function instead of appending one letter at a time:</p>

<pre><code>sentence = input("Enter sentence: ")
split_sentence = sentence.split(" ")
subject = []
subject.append(split_sentence[0])
print (subject)
</code></pre>

<p>or even more simplier:</p>

<pre><code>sentence = input("Enter sentence: ").split(" ")
subject = []
subject.append(sentence[0])
print (subject)
</code></pre>

<p>or even if you are only wanting one input you don't have to append</p>

<pre><code>sentence = input("Enter sentence: ").split(" ")
subject = sentence[0]
print (subject)
</code></pre>

<p><code>split()</code>, splits a string define by the parameter and returns a list. </p>

python while-loop append