I have a data structure like this:
List<Dictionary<string, string[]>>
Key
of dictionary is not important, but Value
array is. I need to count how many values of strings appeared in it together. For example, string array contains these records:
"one"
"one", "two", "four"
"two", "three"
"two", "one", "four"
"one"
"one", "ten"
"two", "four", "one"
The result should look like this:
Value Occurrence
"one" 2
"one", "two", "four" 3
"two", "three" 1
"one", "ten" 1
What I thought and tried to do, was to:
- create a new
Dictionary
to hold results - loop through the
List
using foreach - sort string array in
List<Dictionary>
- check if that string array exists in new
Dictionary
- if it doesn't, add it in
value
and put 1 inkey
- if it does, increment
key
Other than the fact whether it will work or not, I am not even sure if that is an efficient way to do this.