Results 1 to 8 of 8

Thread: Removing duplicate strings in a list

  1. #1
    I could stop if I wanted to
    Join Date
    2003-05
    Posts
    335
    Login to Give a bone
    0

    Default Removing duplicate strings in a list

    Can someone refresh my memory as to what function is used to remove duplicate strings from a list.

    I'm having a brain fart this morning.

    Thanks,
    Will

  2. #2
    100 Club
    Join Date
    2000-12
    Posts
    126
    Login to Give a bone
    0

    Default Re: Removing duplicate strings in a list

    VL-REMOVE would probably be a good choice.

    (vl-remove "hey" '("hey" "this" "is" "a" "bunch" "of" "heys"))
    ("this" "is" "a" "bunch" "of" "heys")

    (vl-remove "heys" '("hey" "this" "is" "a" "bunch" "of" "heys"))
    ("hey" "this" "is" "a" "bunch" "of")

  3. #3
    I could stop if I wanted to
    Join Date
    2003-05
    Posts
    335
    Login to Give a bone
    0

    Default Re: Removing duplicate strings in a list

    stig,

    Thanks for the response. That worked too well I'm afraid.
    Let me clarify what I need. I need to delete all the duplicates except one.

    list would be :
    ("hey" "this" "is" "hey" "a" "bunch" "hey" "of" "heys")

    remove all "hey" duplicates:
    ("hey" "this" "is" "a" "bunch" "of" "heys")

    Does that clarify it a bit?

    Thanks,

  4. #4
    100 Club
    Join Date
    2000-12
    Posts
    126
    Login to Give a bone
    0

    Default Re: Removing duplicate strings in a list

    Hmmm, it clarifies but also makes it a bit more complex. How is the code supposed to know which item to keep? If the first match is to remain then perhaps something like this will do?

    Code:
    (defun removeAllButFirst (item lst / n ll)
      (setq n (cdr (member item lst)))
      (repeat (- (length lst) (length n))
        (setq ll  (cons (car lst) ll)
              lst (cdr lst)))
      (append (reverse ll) (vl-remove item n))
    )

  5. #5
    I could stop if I wanted to
    Join Date
    2003-05
    Posts
    335
    Login to Give a bone
    0

    Default Re: Removing duplicate strings in a list

    I just want it remove all items that are the same except one of them. It doesn't matter which one of them.

    Thanks,

  6. #6
    Member
    Join Date
    2004-02
    Location
    Tampa, Florida
    Posts
    32
    Login to Give a bone
    0

    Default Re: Removing duplicate strings in a list

    I think you want this:

    (vl-remove-if predicate-function list)

    or:

    (vl-remove-if-not predicate-function list)

  7. #7
    100 Club
    Join Date
    2000-12
    Posts
    126
    Login to Give a bone
    0

    Default Re: Removing duplicate strings in a list

    Ah, no need for order, only removing duplicates:

    Code:
    (defun removeDups (item lst / ll)
      (foreach n lst
        (cond ((equal n item)
               (and (not (member item ll))
                    (setq ll (cons n ll))))
              (T (setq ll (cons n ll)))))
      (reverse ll)
    )
    Ok, so it keeps the first occurrence like the former

    Mark, just being curious: which predicate function would you write for VL-REMOVE-IF to remove duplicates?

  8. #8
    I could stop if I wanted to
    Join Date
    2003-05
    Posts
    335
    Login to Give a bone
    0

    Default Re: Removing duplicate strings in a list

    Thanks stig I'll work that into my code and see how it works.

Similar Threads

  1. Duplicate views in View LIst
    By Wish List System in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2013-10-21, 04:53 PM
  2. Removing the double list pairs
    By Ehsan in forum AutoLISP
    Replies: 1
    Last Post: 2012-07-16, 03:47 PM
  3. removing items from list
    By mixted570595 in forum AutoLISP
    Replies: 5
    Last Post: 2012-05-06, 01:47 PM
  4. Removing duplicate vectors
    By geoff.80680 in forum AutoCAD General
    Replies: 4
    Last Post: 2006-08-31, 02:35 PM
  5. Duplicate points removing
    By bprabhakar001 in forum AutoLISP
    Replies: 2
    Last Post: 2005-12-19, 12:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •