Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create an association list from 2 lists?

Tags:

scheme

racket

In DrScheme, how can I create an association list from 2 lists?

For example, I have,

y = ( 1 2 3 )
x = ( a b c )

and I want

z = ((a 1) (b 2) (c 3))
like image 393
pantelis Avatar asked Dec 04 '22 10:12

pantelis


1 Answers

Assuming Scheme (since your last 2 questions are on Scheme):

(define x '(1 2 3))
(define y '(4 5 6))
(define (zip p q) (map list p q))  ;; <----
(display (zip x y))
;; ((1 4) (2 5) (3 6))

Result: http://www.ideone.com/DPjeM

like image 183
kennytm Avatar answered Jan 17 '23 03:01

kennytm