Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: Unique values in hash?
Dan Diebolt
12/16/2008 10:10:00 AM
[Note: parts of this message were removed to make it a legal post.]
h=Hash[*%w(a alex b mary c alex).flatten]
=> {"a"=>"alex", "b"=>"mary", "c"=>"alex"}
irb(main):014:0> h.values
=> ["alex", "mary", "alex"]
irb(main):015:0> h.values.uniq
=> ["alex", "mary"]
--- On Tue, 12/16/08, Vapor .. <vaqas.ashraf@gmail.com> wrote:
From: Vapor .. <vaqas.ashraf@gmail.com>
Subject: Unique values in hash?
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Date: Tuesday, December 16, 2008, 3:48 AM
Hi,
I have a hash that contains duplicate data, for example, :username =>
"alex" comes many times.
I want to loop around and print their names just once (only unique). In
simple loop it would print "alex" repeatedly.
Thanks.
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Unique values in hash?
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