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
  • 74,534
  • 52
  • 194
  • 322
mlzboy
  • 13,836
  • 23
  • 73
  • 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,621
  • 7
  • 28
  • 48
0

You mean, like Array#zip?

Chowlett
  • 44,716
  • 18
  • 112
  • 146