View Problem

Perform an operation on every item of a list

Perform an operation on every item of a list, e.g.
for the list ["ox", "cat", "deer", "whale"] calculate
the list of sizes of the strings, e.g. [2, 3, 4, 5]
DiskEdit
python
print map(lambda x: len(x), ["ox", "cat", "deer", "whale"])
DiskEdit
python
print [len(x) for x in ['ox', 'cat', 'deer', 'whale']]
DiskEdit
csharp .NET 3.5
using System.Collections.Generic;
public class OperationOnEach {
public static void Main() {
var list = new List<string>() { "ox", "cat", "deer", "whale" };
list.ForEach( System.Console.WriteLine );
}
}
DiskEdit
erlang
lists:map(fun (X) ->length(X) end, List).
ExpandDiskEdit
fantom
["ox", "cat", "deer", "whale"].map { it.size }
DiskEdit
groovy
animals = ["ox", "cat", "deer", "whale"]
assert animals*.size() == [2, 3, 4, 5]
DiskEdit
fsharp 1.9.9.9
let lengths = List.map String.length ["ox"; "cat"; "deer"; "whale"]

Submit a new solution for python, csharp, erlang, fantom ...
There are 10 other solutions in additional languages (clojure, cpp, haskell, java ...)