mlzboy
mlzboy

Reputation: 14701

Does ruby have a zip function like python's?

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?

Upvotes: 0

Views: 1339

Answers (2)

fifigyuri
fifigyuri

Reputation: 5899

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"]]

Upvotes: 7

Chowlett
Chowlett

Reputation: 46677

You mean, like Array#zip?

Upvotes: 0

Related Questions