Why do I only print the first letters of each item in the list?
<p>I was wondering why I only print the first letter of each item I input. I would like for it to loop through the list and print each item that starts with one of the letters in the first_letters variable. </p>

<pre><code>phrase = input('Enter a list: ')
first_letters = ['A','B','C','D']
for name in phrase:
    if name[0] in first_letters: 
        print(name)

#['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot']
</code></pre>

<p>Considering your input as: </p>

<pre><code>Alpha, Bravo, Charlie, Delta, Echo, Foxtrot
</code></pre>

<p>This complicates handling your input a bit. Because you are now going to have to deal with a space and a comma between each word.</p>

<p>Upon entering your user input, handle all spaces, and then use <code>split</code> to actually obtain a list of your entries. So: </p>

<pre><code>phrase = input('Enter a list: ').replace(' ', '').split(',')
</code></pre>

<p>phrase will now be a list that looks like:</p>

<pre><code>['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot']
</code></pre>

<p>It would probably easier to just handle a space separated list like: </p>

<pre><code>Alpha Bravo Charlie Delta Echo Foxtrot
</code></pre>

<p>Then, you can just call <code>split()</code> without that <code>replace</code> method, and utilize its default split-on-space: </p>

<pre><code>phrase = input('Enter a list: ').split()
</code></pre>

<p>Now you are iterating over your list and you can now check the first letter of each word with your <code>first_letters</code> list.</p>

<p>To ensure you always compare to the exact same casing, make sure you call <code>upper()</code> for each iteration in your list, to compare to the same case in your list:</p>

<pre><code>phrase = input('Enter a list: ').replace(' ', '').split(',')
first_letters = ['A','B','C','D']
for name in phrase:
    if name[0].upper() in first_letters:
        print(name)
</code></pre>

<p>Output: </p>

<pre><code>Alpha
Bravo
Charlie
Delta
</code></pre>

python