Dupes in list of lists?

Discussion in 'AutoCAD' started by Fatfreek, Aug 6, 2003.

  1. Fatfreek

    Fatfreek Guest

    List variable BoundList contains multiple paired lists of entity names.
    Ename
    7ef71e08 appears twice as a second item and I need a way, after the
    list is built, to detect such duplicates. Any suggestions? Len Miller.

    (
    (<Entity name: 7ef71e00> <Entity name: 7ef71df8>)
    (<Entity name: 7ef71e10> <Entity name: 7ef71e08>)
    (<Entity name: 7ef71e18> <Entity name: 7ef71e08>)
    (<Entity name: 7ef71e18> <Entity name: 7ef71e10>)
    )

    p.s. Yes, 7ef71e18 is a dupe as well but first item dupes are not an issue
    here.
     
    Fatfreek, Aug 6, 2003
    #1
  2. In general, problems like this are solved in the code
    that creates the list, rather than after the fact.

    Where does the list come from? Under most circumstances,
    construction of the list can be constrained to avoid
    adding duplicate elements quite easily.
     
    Tony Tanzillo, Aug 6, 2003
    #2
  3. Fatfreek

    Tom Berger Guest

    (mapcar 'cadr BoundList) returns a list of all secondary elements. You
    simply need to check each item of that list if it is a member of CDR
    of that list. Here the duplicate entities are stored in variable
    duplist:

    (setq blist2 (mapcar 'cadr BoundList))
    (while (and (setq first (car blist2)) (setq blist2 (cdr blist2)))
    (if (member first blist2)
    (setq duplist (cons first duplist))
    )
    )

    Tom Berger
     
    Tom Berger, Aug 6, 2003
    #3
  4. Fatfreek

    Jamie Duncan Guest

    you can begin to constructing a second list very easily

    say l1 and l2

    (foreach i1 l1
    (if (= (member i1 l2) nil)
    (setq l2 (cons i1 l2))
    )
    )



    Jamie Duncan

    Consulting - If you're not part of the solution, there's good money in
    prolonging the problem.
     
    Jamie Duncan, Aug 7, 2003
    #4
  5. Fatfreek

    Fatfreek Guest

    I think I understand your point.

    For example, take that list of lists. By the time I'm ready to place list
    number 3 inside, the main list looks like:
    (
    (<Entity name: 7ef71e00> <Entity name: 7ef71df8>)
    (<Entity name: 7ef71e10> <Entity name: 7ef71e08>)
    )
    List number 3 is ready, (<Entity name: 7ef71e18> <Entity name: 7ef71e08>)
    and can manually see that there is a dupe ready to happen. But I don't know
    how to Lisp it for in reality there may be 30 members in the main list and
    dupes will not necessarily be contiguous as in the case above.
     
    Fatfreek, Aug 7, 2003
    #5
  6. Fatfreek

    John Uhden Guest

    Let's say your list is called Pairs, and the pair to be added is called Pair.
    Then...
    (or
    (vl-position (cadr Pair)(mapcar 'cadr Pairs))
    (setq Pairs (cons Pair Pairs))
    )
     
    John Uhden, Aug 7, 2003
    #6
  7. Fatfreek

    Fatfreek Guest

    Yes, you are correct that the second element must be unique so I will take
    your tip in reversing their order -- then see if I can understand and follow
    your recipe to solve my problem.
     
    Fatfreek, Aug 7, 2003
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.