Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: how to remove dups from 2 lists?
Harry Kakueki
5/11/2007 3:52:00 AM
On 5/11/07, Mike Steiner <mikejaysteiner@gmail.com> wrote:
> I'm trying to write some code that removes all elements from 2 lists that
> are in both lists. However, I don't want any duplicates from each list
> deleted also (which is what the array "-" operator does). The code I have
If I understand correctly, I think this does what you want.
arr1 = %w[a a a b b b c d d e e]
arr2 = %w[a b b b c c c d d d d d e a b]
str1 = arr1.to_s
str2 = arr2.to_s
(arr1 & arr2).each do |x|
str1.sub!(x,"")
str2.sub!(x,"")
end
p str1.split(//).to_a
p str2.split(//).to_a
Harry
--
http://www.kakueki.com/ruby...
A Look into Japanese Ruby List in English
1 Answer
Harry Kakueki
5/11/2007 3:56:00 AM
0
On 5/11/07, Harry Kakueki <list.push@gmail.com> wrote:
> On 5/11/07, Mike Steiner <mikejaysteiner@gmail.com> wrote:
> > I'm trying to write some code that removes all elements from 2 lists that
> > are in both lists. However, I don't want any duplicates from each list
> > deleted also (which is what the array "-" operator does). The code I have
>
> If I understand correctly, I think this does what you want.
>
Oops! Correction.
arr1 = %w[a a a b b b c d d e e]
arr2 = %w[a b b b c c c d d d d d e a b]
str1 = arr1.to_s
str2 = arr2.to_s
(arr1 & arr2).each do |x|
str1.sub!(x,"")
str2.sub!(x,"")
end
p str1.split(//)
p str2.split(//)
--
http://www.kakueki.com/ruby...
A Look into Japanese Ruby List in English
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: how to remove dups from 2 lists?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password