Re: Collecting like-labelled sublists of a list



På Wed, 30 Jul 2008 04:11:00 +0200, skrev Thomas A. Russ <tar@xxxxxxxxxxxxx>:


To see the effect, try the following:

(defvar *input* (copy-tree '((0 a b)
(1 c d)
(2 e f)
(3 g h)
(1 i j)
(2 k l)
(4 m n)
(2 o p)
(4 q r)
(5 s t))))

;; I use copy-tree to avoid problems with destructively modifying
;; constant list structure.

(test *input*)
=> ((A B) (C D I J) (E F K L O P) (G H) (M N Q R) (S T))

*input*
=> ((0 A B) (1 C D I J) (2 E F K L O P) (3 G H) (1 I J)
(2 K L O P) (4 M N Q R) (2 O P) (4 Q R) (5 S T))

Note in particular the changes to the first occurences of the lists
headed by 1, 2 and 4.


If your files are as big as you mentioned 25 Mb or more a buffered approach sounds better unless you have a pressing need to keep it all in memory.

--------------
John Thingstad
.