If i have two arrays containing about 20 separate values is it possible to combine the two into a hash? With the contents of one array acting as the keys and the other as the values?
Asked
Active
Viewed 164 times
1 Answers
0
Sure, very simple
Hash[[1,2,3,4].zip([5,6,7,8])]
=> {1=>5, 2=>6, 3=>7, 4=>8}
But it might be a problem if the arrays have not the same size.

Ursus
- 29,643
- 3
- 33
- 50
-
I wonder how sometimes answers appear after the question is closed/marked as duplicate/whatever else - might be a bug or something in SO :) – Andrey Deineko Feb 03 '17 at 14:40
-
Probably I answered one second before :P – Ursus Feb 03 '17 at 14:43
-
hm, I am sure (at least on the GUI) that when I marked it as duplicate there were no questions, and even more - I reloaded the page and still it didn't have the answer, so interesting :) – Andrey Deineko Feb 03 '17 at 14:44
-
@ursus Thank you! – Tiago Feb 03 '17 at 14:53
-
My pleasure Sir :) – Ursus Feb 03 '17 at 14:54