In Beginning Student with List Abbreviations
I am struggling to come up with functions to remove duplicates from a list while maintaining the order of the list. one function to remove duplicates from the left, i.e. 1 2 1 3 2 4 5 -> 1 2 3 4 5 and one from the right. i.e. 1 2 1 3 2 4 5 -> 1 3 2 4 5 What are the functions for removing duplicates from each left and right side? If you need to, use helper functions and append, cond, cons, equal?, etc but not using reverse or any built-in functions. For example, with unique-left I came up with the below code but it only removes any consecutive duplicates e. g. (list 2 3 4 4 5 3) -> (list 2 3 4 5 3) ;(define (unique-left lst) ; (cond ; [(empty? lst) 0] ;[(empty? (rest lst)) lst] ;[else ; (if (equal? (first lst) (first (rest lst))) ; (unique-left (rest lst)) ; (cons (first lst) (unique-left (rest lst))))])) So the code does not get me the unique-left like I want to show as the top example. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/4739e5ce-d328-4d09-859a-bacac2b1989fn%40googlegroups.com.