How to change something in a list


#1

Basically, I have an assignment where I have to create a program that reads multiple lines of text from a user, prints out each different word and how many times each of these words was said. I then have to print each in Alphabetical order.

My code thus far is basically stuck on what to do if the word is already in the list I created to store the unique words. How do I change an entry?

Also, how would I go about printing each key on a new line? For example, 6 unique words, these are By, Caught, Fish, Me, The, Was, and I want to print each out on a separate line without knowing how many unique words there would be at the start as it takes user input which will be from my teacher after reading the code.


#2

This is all stuff you should have some understanding of so I don’t see how it could be a question we can answer. Given some of your code, we might be able to add insight, though.


#3

This is my current code. Bits and pieces have parts missing where I don’t understand currently.

Text_Original = str(raw_input("Insert sentence here: "))

def how_many():
word_count = []
for word in Text_Original:
if word in word_count:
else:
word_count.append(word)
return word_count
print word_count

how_many()

image