View Problem

From a List Produce a List of Duplicate Entries

Taking a list:
["andrew", "bob", "chris", "bob"]

Write the code to produce a list of duplicates in the list:
["bob"]
DiskEdit
python 2.4
import itertools
input = ["andrew", "bob", "chris", "bob"]
input.sort()
output = [k for k, g in itertools.groupby(input, lambda x: x) if len(list(g)) > 1]
DiskEdit
fsharp
["andrew"; "bob"; "chris"; "bob"]
|> Seq.countBy id
|> Seq.filter (fun (k,n) -> n > 1)
|> Seq.map fst
|> Seq.toList
ExpandDiskEdit
fantom
nameCounts := Str:Int[:] { def = 0 }
["andrew", "bob", "chris", "bob"].each |Str v| { nameCounts[v]++ }
results := nameCounts.findAll |Int v, Str k->Bool| { v > 1 }.keys
echo(results.join(","))
DiskEdit
groovy 1.7.6
def input = ["andrew", "bob", "chris", "bob"]

def output = input.findAll{input.count(it)>1}.unique()

assert output == ["bob"]
DiskEdit
haskell
import Data.List

input = ["andrew", "bob", "chris", "bob"]
output = [ head l | l <- group (sort input), length l > 1]

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