Count how many times a word appears in a text file

user5367640
def paraula(file,wordtofind):

    f = open(file,"r")
    text = f.read()
    f.close()
    count = 0
    for i in text:
        s = i.index(wordtofind)
        count = count + s
    return count
paraula (file,wordtofind)
mbinette
def paraula(file,wordtofind):
    f = open(file,"r")
    text = f.read()
    f.close()
    count = 0
    index = text.find(wordtofind) # Returns the index of the first instance of the word
    while index != -1:
        count += 1
        text = text[index+len(wordtofind):] # Cut text starting from after that word
        index = text.find(wordtofind) # Search again
    return count

paraula (file,wordtofind)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to count how many times each individual word appears in text file

From Dev

how to count how many times each word appears?

From Dev

Is there a way to count how many times a specific word appears in R

From Dev

Excel: How to count how many times a consecutive text value appears

From Dev

Regular expressions - counting how many times a word appears in a text

From Dev

How to check how many times a word appears in a txt file in php?

From Dev

Count how many times appears text across columns

From Dev

How to count how many times each line appears in a file

From Dev

How to count the number of times a word is in the text file

From Dev

How to count the times a word appears in a file using a shell?

From Java

Count the number of times a word appears in a file

From Dev

How to count the number of times a character symbol appears in a text file?

From Dev

Count How Many Times a Value Appears Php

From Dev

SQL COUNT how many times a value appears

From Dev

Count how many times a value appears in this array?

From Dev

Count how many number of times a value appears

From Dev

Python: Count how many times a word occurs in a file

From Dev

EXCEL: I want to count how many times a certain word appears in a column if it's in the same row if another word appears

From Dev

Excel - how to count how many times a word appears within a certain date range

From Dev

How to count the times a specific character appears in a file?

From Dev

Count how many times a word exist in column

From Dev

How to count the number of times a word sequence appears in a file, using MapReduce in Python?

From Dev

Count number of times a word appears

From Dev

Count the ammount of times a word is repeated in a text file

From Dev

How to check how many times a number appears in a specific line inside a text file

From Python

How to count how many times an entity appears with another entity

From Python

Recursion function to count how many times a certain sequence appears

From Dev

count how many times a row appears in a different dataset

From Dev

Count how many times each token appears in each rows of a DataFrame

Related Related

  1. 1

    How to count how many times each individual word appears in text file

  2. 2

    how to count how many times each word appears?

  3. 3

    Is there a way to count how many times a specific word appears in R

  4. 4

    Excel: How to count how many times a consecutive text value appears

  5. 5

    Regular expressions - counting how many times a word appears in a text

  6. 6

    How to check how many times a word appears in a txt file in php?

  7. 7

    Count how many times appears text across columns

  8. 8

    How to count how many times each line appears in a file

  9. 9

    How to count the number of times a word is in the text file

  10. 10

    How to count the times a word appears in a file using a shell?

  11. 11

    Count the number of times a word appears in a file

  12. 12

    How to count the number of times a character symbol appears in a text file?

  13. 13

    Count How Many Times a Value Appears Php

  14. 14

    SQL COUNT how many times a value appears

  15. 15

    Count how many times a value appears in this array?

  16. 16

    Count how many number of times a value appears

  17. 17

    Python: Count how many times a word occurs in a file

  18. 18

    EXCEL: I want to count how many times a certain word appears in a column if it's in the same row if another word appears

  19. 19

    Excel - how to count how many times a word appears within a certain date range

  20. 20

    How to count the times a specific character appears in a file?

  21. 21

    Count how many times a word exist in column

  22. 22

    How to count the number of times a word sequence appears in a file, using MapReduce in Python?

  23. 23

    Count number of times a word appears

  24. 24

    Count the ammount of times a word is repeated in a text file

  25. 25

    How to check how many times a number appears in a specific line inside a text file

  26. 26

    How to count how many times an entity appears with another entity

  27. 27

    Recursion function to count how many times a certain sequence appears

  28. 28

    count how many times a row appears in a different dataset

  29. 29

    Count how many times each token appears in each rows of a DataFrame

HotTag

Archive