Python Forum

Full Version: Counting words in text
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, can you explain to me, how to count words in some text and make a list consisting of couples in form: [(word, number of appearances),(word,number),(word,number)...]?

Thanks in advance for your help.
show us what you have done so far, and where you are having trouble.
Ok, but none of my attempts was succesful.

I was thinking about creating 2 lists - one consisting of all different words and the second one of numbers - whilst list2[0] represents number of appearances of word list1[0] and so on. But the problem with this is, that it´s no way how am I able to create one list with these couples, or at least I don´t know how to such a couple list create, from syntax aspect.
pseudo code:
for item in list1:
    if item in list2:
        ...
Thanks, I have done it. :)