View Problem

Gather together corresponding elements from multiple lists

Given several lists, gather together the first element from every list, the second element from every list, and so on for all corresponding index values in the lists. E.g. for these three lists, first = ['Bruce', 'Tommy Lee', 'Bruce'], last = ['Willis', 'Jones', 'Lee'], years = [1955, 1946, 1940] the result should produce 3 actors. The middle actor should be Tommy Lee Jones.
ExpandDiskEdit
fsharp
let result = (List.zip3 first last years)
ExpandDiskEdit
cpp C++/CLI .NET 2.0
array<String^>^ first = {"Bruce", "Tommy Lee", "Bruce"}; array<String^>^ last = {"Willis", "Jones", "Lee"}; array<String^>^ years = {"1955", "1946", "1940"};

array<String^>^ result = zip<String^>(",", first, last, years);
ExpandDiskEdit
cpp C++11 (gcc 4.6/VC++ 2010)
list<string> first = { "Bruce", "Tommy Lee", "Bruce" };
list<string> last = {"Willis", "Jones", "Lee"};
list<int> years = {1955, 1946, 1940};
list<tuple<string,string,int> > actors;

for (firstIt = first.begin(), lastIt = last.begin(), yearIt = years.begin();
firstIt != first.end() && lastIt != last.end() && yearIt != years.end();
++firstIt, ++lastIt, ++yearIt)
actors.push_back(make_tuple(*firstIt, *lastIt, *yearIt));
ExpandDiskEdit
fantom
r := [,]
first.size.times |Int i| { r.add([first[i], last[i], years[i]]) }

echo(r)

Submit a new solution for fsharp, cpp, or fantom
There are 16 other solutions in additional languages (clojure, csharp, erlang, groovy ...)