+ 1
Count occurrences in column
Hello, I’ve data with a column that has many occurrences. For example in a line you can find two words or more, there’s 21000 lines. How do I know the number times that a word appears without knowing the word? Thanks
2 Respuestas
+ 9
Hmm... I don't know which language this is for, or if you want to total everything or prompt for a wanted word. But it might work something like this:
Store 21000 lines in a file
Copy file contents to string variable
Make a dictionary, 2 lists (string for words, int for occurrences), or 1 list of objects (string word, int count)
While not at end of file
string word
While current char in file isn't a space
Read 1 char
If char not punctuation
Add to word
end while
If word not in array/dictionary/list
Add to list
If word is in list
occurrences += 1 //Adds to number of occurrences for that word
Advanced forward 1 char to skip space
end while
for each item in list/array/dictionary
print word, print occurrences
+ 3
Speaking the power of variables and comparison, its possible. but which language /?