0

I am a newibe from python to ruby.

In python there is a feature like the following:

a=range(3)
b=range(3)
for e1,e2 in zip(a,b)
    print e1,e2

Is there something that can achieve the same function in ruby?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
mlzboy
  • 14,343
  • 23
  • 76
  • 97

2 Answers2

7

That is what Array#zip does:

foo = [1,2,3,4]
bar = ['a','b','c','d']

foo.zip(bar) #=> [[1, "a"], [2, "b"], [3, "c"], [4, "d"]]
fifigyuri
  • 5,771
  • 8
  • 30
  • 50
0

You mean, like Array#zip?

Chowlett
  • 45,935
  • 20
  • 116
  • 150