View Problem

Join the elements of a list, separated by commas

Given the list [Apple, Banana, Carrot] produce "Apple, Banana, Carrot"
DiskEdit
python
print ", ".join(['Apple', 'Banana', 'Carrot'])
DiskEdit
csharp .NET 3.5
using System.Collections.Generic;
public class JoinEach {
public static void Main() {
var list = new List<string>() {"Apple", "Banana", "Carrot"};
System.Console.WriteLine( string.Join(", ", list.ToArray()) );
}
}
ExpandDiskEdit
erlang
Result = string:join(Fruit, ", "),
ExpandDiskEdit
erlang
Result = lists:foldl(fun (E, Acc) -> Acc ++ ", " ++ E end, hd(Fruit), tl(Fruit)),
ExpandDiskEdit
erlang
Result = lists:flatten([ hd(Fruit) | [ ", " ++ X || X <- tl(Fruit)]]).
ExpandDiskEdit
fantom
["Apple", "Banana", "Carrot"].join(", ")
ExpandDiskEdit
groovy
string = fruit.join(', ')
ExpandDiskEdit
groovy
string = fruit.toString()[1..-2]
ExpandDiskEdit
go
s := strings.Join([]string {"Apple", "Banana", "Carrot"}, ", ")

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