View Problem
Categorise a list
Given the list
Submit a new solution for fsharp, erlang, clojure, or csharp
There are 18 other solutions in additional languages (cpp, fantom, groovy, haskell ...)
[one, two, three, four, five] produce a map {3:[one, two], 4:[four, five], 5:[three]} which sorts elements into map entries based on their length
csharp .NET 3.5
using System.Collections.Generic;
using System.Linq;
public class ListCategorizer {
public static void Main() {
var list = new List<string>() { "one", "two", "three", "four", "five" };
var categories = list.GroupBy(el => el.Length)
.ToDictionary( g => g.Key, // key
g => g.ToList() ); // value
}
}
using System.Linq;
public class ListCategorizer {
public static void Main() {
var list = new List<string>() { "one", "two", "three", "four", "five" };
var categories = list.GroupBy(el => el.Length)
.ToDictionary( g => g.Key, // key
g => g.ToList() ); // value
}
}
Submit a new solution for fsharp, erlang, clojure, or csharp
There are 18 other solutions in additional languages (cpp, fantom, groovy, haskell ...)




