I still think I would go for the best code I can, but code that works will do for a start. Have you actually got code that works; I don't think you do.Cody Biggs wrote:. . . the instructor has already taken a look, and approved I would rather keep it.
That is what I thought. Similar to Java®, only in Java® you would use Integer rather than int.My dictionary is Dictionary<String, int> the String being the key which are just words from a text file, and int representing the value of how many times that word is read.
Again as I thought, which means you can't get the total number of words from Count.. . . regarding count . . . I guess that would for the number of different words.
Don't understand that bit. The three methods seem to do the same thing, which is to return the number of times a word appears. I don't think you will get anywhere with three identical methods, nor do I think that −1 is correct. If you use such methods for adding word counts, you will only get the right answer if you return 0. But I don't think those methods willl be the best way for a total of words.. . . I am just looking for how many times count, may and color are read. . . .
Surely KeyValuePair returns a key‑value pair which has already been defined?The main methods talked about are containsKey, containsValue, count, trygetvalue, and also keyvaluepair which defines a key/value pair that can be retrieved.
That looks promising. Once you have worked out how to walk the entire dictionary, it is really simple to add up all the individual counts. And, in the same loop, you can also find the word with the highest count. That isn't difficult. I suggest you get a sheet of paper and write on it how you would go through such a dictionary. Decide what you will do if you find two words with the same highest count (take the first‑found???), and then work out how you are going to record all these results.. . . I can walk through each pair in the dictionary and get the key/value of the pair . . .
Of course you can get both back. You need a bit of object‑oriented thinking.Cody Biggs wrote:but I couldnt do that could I? Key is a string and value is an int, so I cant return both
nonononononononononononoCody Biggs wrote:Unless I did two methods. Same loop one returns the key, and the other the value? . . . .
Cody Biggs wrote:but I couldnt do that could I? Key is a string and value is an int, so I cant return both
There are three kinds of actuaries: those who can count, and those who can't.
Cody Biggs wrote:"the" is the first word that is in the dictionary, but after messing with the text file, and replacing the with another word my key is still "the" that gets returned. So its doing what its suppose to.
Now that looks right You could return the pair, in which case you get both word and frequency, as PS told you yesterday.Cody Biggs wrote:just fixed some stuff. Added the return outside the for loop. . . .
straws are for suckers. tiny ads are for attractive people.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|