Guys, how do I add an item to a list using a loop?
My loop in a nutshell does this:

for w in book_line.split(" "):
            word_list = []
            if w != "":
                word_list.append(w.lower())
                return word_list

While experimenting with this I got mainly two results:

1.) When I use return word_list, it only puts the first word of the book into my list.

2.) When I use print word_list I prints just one word as well. but goes through each word individually.

I also tried putting word_list = [] in different parts of the code, and that opened up a whole new can of worms. :(

Question: How do I "dump" the results from my for loop(the words). into my list without having them cancel each other out?

word_list = []
for w in book_line.split(" "):
    if w != "":
        word_list.append(w.lower())
print word_list

Indentation is very important.

Tried that. It returns a bunch of different lists. Some empty :(

anyone?

Got it. I even indented Gribouillis answer wrong lol.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.