Remove integers from list

2019-06-14 15:12发布

问题:

I have a strange problem that couple of hours can't implement in Scheme. Let's say we have:

(define x '( (Orlando (NY 3))
             (Chicago (Montana 5) (Orlando 8))
             ...and so on ...
           )

I want to transform it to

'( (Orlando NY)
   (Chicago Montana Orlando)
    ...and so on ...
 )

Any help would be greatly appreciated.

回答1:

You could also try

(map 
 (lambda (x) (cons (car x) (map car (cdr x)))) 
 x)