- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a list of real numbers and some numbers repeat, but they are all in increasing order for example (123.12 124.2 125.25 125.28 125.28 127.1 128 128.5 129 130 130 131 132 132.5)
How do I get this list ((123.12 . 124.2) (125.25 . 125.28) (125.28 . 127.1) (128 . 128.5) (129 . 130) (130 . 131) (132 .132.5))
Tried using mapcar as follows
(mapcar '(lambda (x y) (cons x y)) lstlst (cdr lstlst))
but what I get is this ((123.12 . 124.2) (124.2 . 125.25) (125.25 . 125.28) (125.28 . 125.28) (125.28 . 127.1) (127.1 . 128) (128 . 128.5) (128.5 . 129) (129 . 130) (130 . 130) (130 . 131) (131 . 132) (132 . 132.5)) as you can see now I need to get rid of 2nd, 4th, 6th, 8th etc. members. Any tips? Maybe I can somehow modify the above mapcar to get the right result. Thanks. Infact, the order of original numbers (I mean sorted or not sorted) does not even matter. All I care is to cons 1st and 2nd memebr, then 3rd and 4th, then 5th and 6th and so on and get me a new list.
Solved! Go to Solution.