Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created April 30, 2009 14:20
Show Gist options
  • Save atifaziz/104468 to your computer and use it in GitHub Desktop.
Save atifaziz/104468 to your computer and use it in GitHub Desktop.
// turns a sequence of key to many values into a new sequence
// where each value of a key from the first sequence becomes
// the a key in the second sequence and where its only value
// is its key from the first sequence. Example:
//
// [1, [one, un, einz]]
// [3, [two, deux, zwei]]
// [2, [three, trois, drei]]
//
// becomes:
//
// [one, 1]
// [un, 1]
// [einz, 1]
// [two, 2]
// [deux, 2]
// [zwei, 2]
// [three, 3]
// [trois, 3]
// [drei, 3]
new KeyValuePair<int, string[]>[] {
new KeyValuePair<int, string[]>(1, "one un einz".Split()),
new KeyValuePair<int, string[]>(2, "two deux zwei".Split()),
new KeyValuePair<int, string[]>(3, "three trois drei".Split()),
}
.SelectMany(e => e.Value.Select(v => new KeyValuePair<string, int>(v, e.Key)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment