From: Enrique Comba Riepenhausen Date: 2007-05-11T17:27:31+09:00 Subject: Re: how to remove dups from 2 lists? On 11 May 2007, at 10:23, Brian Candler wrote: > On Fri, May 11, 2007 at 04:55:14PM +0900, Enrique Comba > Riepenhausen wrote: >> Do you want to remove the elements that are in the same position on >> the lists and are equal? >> >> If so I would say: >> >> require 'generator' >> >> list1 = [1,1,2,3,4,6] # => I included the 6 to show what I mean... >> list2 = [2,2,3,5,5,6] # => I included the 6 to show what I mean... >> >> def RemoveDupsFromLists ( list1 , list2 ) >> lists = SyncEnumerator.new(list1, list2) >> lists.each { |element_list1, element_list2| >> >> if list1[element_list1] == list2[element_list2] >> list1.delete(element_list1) >> list2.delete(element_list2) >> end >> } >> end > > Is it safe to delete from lists while you're enumerating through them? Actually not ;) It depends if other objects are trying to access those lists at the same time though...