[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Subject: Re: duplicates

William James

11/17/2015 5:01:00 PM

> Just wanted to confirm I hadn't missed any obvious solution before
> rolling my own version. Thanks for the replies!
>
> I ended up with something like:
>
> (defun duplicates (list)
> (let ((h (make-hash-table)))
> (iter (for x in list)
> (for i from 0)
> (cond ((gethash x h)
> (push i (gethash x h)))
> (t (setf (gethash x h) (list i)))))
> (iter (for (key value) in-hashtable h)
> (when (> (length value) 1)
> (collect (list key value))))))
>
> MSINGH> (duplicates '(1 2 4 4 5 x x y y z))
> ((4 (3 2)) (X (6 5)) (Y (8 7)))

MatzLisp (Ruby):

def duplicates ary
ary.each_with_index.group_by{|x,i| x}.
reject{|k,v| v.one?}.map{|k,v| [k, v.map(&:last)]}
end

duplicates %w(1 2 4 4 5 x y x y z)

==>[["4", [2, 3]], ["x", [5, 7]], ["y", [6, 8]]]

--
Arrogant and isolated, the elite treat the ordinary citizens of the empire as
slaves and potential enemies.
www.kolumbus.fi/aquilon/america-middle-class-and-the-end-of-growth.htm
1 Answer

The Peeler

6/6/2013 10:18:00 PM

0

On Fri, 7 Jun 2013 00:08:37 +0200, The Peeler
<finishingoff@themoronicRevd.invalid> wrote:

>>> Ayup!
>>
>> A semite is a semite, even when posing as a black - ass! LOL1
>
><BG> Once an asshole, always an asshole, eh, "The Rectum"?

<GB> You've, ALWAYS been an asshole Grik anus!