Jason Roelofs
1/4/2008 12:18:00 AM
[Note: parts of this message were removed to make it a legal post.]
On Jan 3, 2008 7:13 PM, MenTaLguY <mental@rydia.net> wrote:
> On Fri, 4 Jan 2008 08:49:54 +0900, Holden Holden <pyarnau@gmail.com>
> wrote:
> > Python:
> >
> > list(enumerate(['a','b','c']))
> > => [(0, 'a'), (1, 'b'), (2, 'c')]
> >
> > Ruby:
> >
> > t = []; ['a','b','c'].each_with_index { |*x| t << x }; t
> > => [["a", 0], ["b", 1], ["c", 2]]
> >
> > Which is a very ugly solution. How could I do this on Ruby without a
> > temporal variable?
>
> Try this (you will need to require 'enumerator'):
>
> ['a','b','c'].enum_with_index.to_a
>
> -mental
>
>
Ah, that's where enum_with_index is. I was wondering why it wasn't working
for me.
Jason