Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Counting words in text
#1
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.
Reply
#2
show us what you have done so far, and where you are having trouble.
Reply
#3
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.
Reply
#4
pseudo code:
for item in list1:
    if item in list2:
        ...
Reply
#5
Thanks, I have done it. :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Form that puts diacritics on the words in the text Melcu54 13 1,381 Aug-22-2023, 07:07 AM
Last Post: Pedroski55
  Extract a string between 2 words from a text file OscarBoots 2 1,826 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,756 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Open and read multiple text files and match words kozaizsvemira 3 6,666 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Counting number of words and organize for the bigger frequencies to the small ones. valeriorsneto 1 1,642 Feb-05-2021, 03:49 PM
Last Post: perfringo
  Counting the most relevant words in a text file caiomartins 2 2,444 Sep-21-2020, 08:39 AM
Last Post: caiomartins
  Check text contains words similar to themes/topics (thesaurus) Bec 1 27,867 Jul-28-2020, 04:17 PM
Last Post: Larz60+
  Counting words in the last line of a file Drone4four 15 6,376 May-31-2019, 09:30 PM
Last Post: snippsat
  Compare all words in input() to all words in file Trianne 1 2,716 Oct-05-2018, 06:27 PM
Last Post: ichabod801
  Python - Limit Sentence Length to 10 Words - Text file dj99 2 5,111 Jul-21-2018, 02:24 PM
Last Post: dj99

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020