2

I have 2 lists:

(Define list1 '("xx1" "xx2" xx3" "xx4" "xx5"))
(Define list2 '("xx2" "xx4" "xx5"))

the items in the list above are just an example, but either way it will be a string item. What I need to do is compare both lists and remove the items in list1 that are found in list2.

is there a short map routine i can do?

this isn't some homework project, I wish there was a course here for programming classes though :/

adao7000
  • 3,632
  • 2
  • 28
  • 37
  • possible duplicate of [Common elements in two lists with duplicates](http://stackoverflow.com/questions/18152062/common-elements-in-two-lists-with-duplicates) – Crembo Jun 11 '15 at 09:52
  • Programming class following Racket language: [How to design programs](http://www.htdp.org/). Scheme standard [SICP](http://mitpress.mit.edu/sicp/full-text/book/book.html) and a [video course](https://www.youtube.com/watch?v=2Op3QLzMgSY&list=PL8FE88AA54363BC46) by the magicians on MIT opencourseware (R4RS, but mostly compatible with todays Scheme and `#!racket`. There is a [SICP compability package](http://stackoverflow.com/a/25096066/1565698)) – Sylwester Jun 11 '15 at 14:28

2 Answers2

1

There's also remove*

An example:

#lang racket
(define list1 '("xx1" "xx2" "xx3" "xx4" "xx5"))
(define list2 '("xx2" "xx4" "xx5"))

(displayln (remove* list2 list1))

Prints:

(xx1 xx3)
minikomi
  • 8,363
  • 3
  • 44
  • 51
0
#lang racket
(define list1 '("xx1" "xx2" "xx3" "xx4" "xx5"))
(define list2 '("xx2" "xx4" "xx5"))

(for/list ([x (in-list list1)]
           #:unless (member x list2))
  x)

Result:

 '("xx1" "xx3")
soegaard
  • 30,661
  • 4
  • 57
  • 106