I am trying to create a program that reads a .txt file, displays it, counts unique words and displays unique words next to how many times used. So far I have the number of total unique words and the unique words used. I am a little stuck on how to count the number of times each word was used rather than just the overall total of unique words. How would I display the text from the file as well? My current print statement prints the word the number of times it appears and I want to change it to something like this: " as: 6 " etc...in alphabetical order. Any suggestions or help would be appreciated.
So I completely revamped my program using map and fixed some other problems. I just can't print out the text file. Above the sorted words and how many times they appear, I want to display the text from the file. How would I do that? I tried several thing but it either does nothing or screws up the rest of the code saying there are 0 unique words. And lastly how would Print out the results so they are more ... table -ish...
Something like this:
Word: [equal spaces] Count:
ask [equal spaces] 5
anger [equal spaces] 3