'Need help in understanding why for loop didn't iterate whole list, yet while did

I'm just beginning Python and I wanted to write some functions based on an exercise, and then call these functions from another function, all to extract first letters from each word in a string.

At first I tried a for loop but it didn't iterate through the whole list of words; only halfway. But a while loop did. Yet when I had the for loop just iterate the list and print out each element it worked. I'm struggling to identify why and hope someone can help me understand.

def all_first_letters(sentence):
words = take_words_from_sentence(sentence)
while words != []:
    focal1 = first_word_in_list(words)
    litreacha = split_word_into_chars(focal1)
    litir = first_letter_popped(litreacha)
    add_to_list(litir)

This function works and takes a sentence, breaks it into a list of words, pops off the first word, then pops of the first letter of that, appends the letter to a list and then repeats until I end up with a list of initials of each word. But when I tried it first with a for loop;

def all_first_letters(sentence):
words = take_words_from_sentence(sentence)
for word in words:
    focal1 = first_word_in_list(words)
    litreacha = split_word_into_chars(focal1)
    litir = first_letter_popped(litreacha)
    add_to_list(litir)

It would never iterate through the whole sentence. If I gave it a sentence of three words I got two letters; if five I got three letters, and of ten words it returned five.

My puzzle is why the for loop doesn't go through each element of the list words yet the while loop does.

I hope there's enough information here to understand without giving every function.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source