select column from two-dimension list

Started by Dmi, November 03, 2005, 07:09:00 AM

Previous topic - Next topic

Dmi

Is there a more simple way to do this:
(define (select-column lst col)
  (let l '()
    (dolist (i lst)
       (push (i col) l -1))
   l))
WBR, Dmi

Sammo

#1
(define (select-column lst col)
   (map (fn (row) (row col)) lst) )

Dmi

#2
I'm stupid today! :-)

Thanx!
WBR, Dmi

Fanda

#3
Not really from my head :-)


> (setq L '((1 2) (3 4) (5 6)))
((1 2) (3 4) (5 6))
> (transpose L)
((1 3 5) (2 4 6))
> ((transpose L) 0)
(1 3 5)
> ((transpose L) 1)
(2 4 6)
>


It should be fast too...



Fanda