[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Making a count of unique elements in an array

Peña, Botp

1/9/2006 7:08:00 AM

Dan Kohn [mailto:dan@dankohn.com] wrote:

#counter = {}
#arr.each {|e| counter[e] += 1 rescue counter[e] = 1 }
#p counter.to_a

me, like the above but w slight modif below:

irb(main):013:0> counter2 = Hash.new(0)
=> {}
irb(main):014:0> arr.each {|e| counter2[e] += 1 }
=> ["a", "b", "b", "c", "c", "d", "e", "e", "e"]
irb(main):015:0> counter2.to_a
=> [["a", 1], ["b", 2], ["c", 2], ["d", 1], ["e", 3]]
irb(main):016:0>

(note the plain counter and the hash param)

hth.

kind regards -botp


1 Answer

Eddie Haskell

12/2/2010 8:05:00 PM

0


"Ray Fischer" <rfischer@sonic.net> wrote in message
news:4cf7f477$0$1625$742ec2ed@news.sonic.net...
> Eddie Haskell <jhjhjhj@sasasqq.com> wrote:
>>
>>"Ray Fischer" <rfischer@sonic.net> wrote in message
>>news:4cf72580$0$1646$742ec2ed@news.sonic.net...
>>> Dave Heil <k8mn@frontiernet.net> wrote:
>>>>On 12/1/2010 15 20, Yoorghis@Jurgis.net wrote:
>>>>> On Wed, 01 Dec 2010 05:21:56 +0000, Dave Heil<k8mn@frontiernet.net>
>>>>> wrote:
>>>>>
>>>>>> On 12/1/2010 04 28, Yoorghis@Jurgis.net wrote:
>>>>>>
>>>>>>> After Jan 2003----NONE of what we "thought" Saddam had----was true
>>>>>>>
>>>>>>> BUsh knew that before he attacked
>>>>>>>
>>>>>>> That's the facts, evidence and truth of the matter
>>>>>>>
>>>>>>> Bush invaded Iraq based on lies and false reasons
>>>>>>
>>>>>> ...to the best of your limited knowledge.
>>>>>>
>>>>>
>>>>> No---according to the evidence produced after Dec 2002 and the
>>>>> invasion of Iraq proved.
>>>>
>>>>None of what you say is fact. World governments shared our views based
>>>>upon intelligence and on Saddam's own claims.
>>>
>>> You're a lying little turd. Bush TRIED to get the UN Security Council
>>> to go along with his invasion but they REFUSED. Except for Britain,
>>> nobody bought into the lies.
>>
>>You're lying.
>
> You're a crazy rightard asshole.

Did you shit your pants when you darted for the delete key?

Not to worry..

http://en.wikipedia.org/wiki/Coalition_of_t...

-Eddie Haskell