Dupes in list of lists?

Fatfreek

Usenet Archive
Joined
Oct 26, 2000
Messages
96
Reaction score
0
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.
 
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.
 
Fatfreek said:
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.

(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
 
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.
 
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.
 
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))
)
 
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.
 

Latest threads

Back
Top