From: Michael Neumann Date: 2001-10-11T19:31:46+09:00 Subject: [ruby-talk:22427] Re: list comprehensions alike Python ??? Robert Feldt wrote: > On Thu, 11 Oct 2001, Paul Prescod wrote: > > > Out of curiousity, what would the Ruby for this look like: > > > > >>> arr = [x*x for x in range(0,10) if x%2==0] > > >>> arr > > [0, 4, 16, 36, 64] > > > > A combination of filter and map? > > > One alternative is: > irb(main):001:0> (0...10).select{|v| v%2==0}.map{|v| v*v} > [0, 4, 16, 36, 64] Shorter (but with external array): irb(main):001:0> a=[]; 0.step(10,2) {|i| a<