When I saw a senior who used a C ++ pair to process an x-axis array and a y-axis array as a set, I thought it was cool, but python also had a function called zip. I don't know
zip
x = [1, 2, 3]
y = [4, 5, 6]
z = zip(x, y)
You should now have [(1, 4), (2, 5), (3, 6)] assigned to z!
z
<zip object at 0x104d232c8>
that? It seems that the return value of the zip was changed from list in python2 to iterator in python3 ([Porting code to Python 3 using 2to3](http://diveintopython3-ja.rdy. jp / porting-code-to-python-3-with-2to3.html)).
zip2list
list(z) # [(1, 4), (2, 5), (3, 6)]
did it!
~~ I tried to find the same thing in PHP, but I didn't like it because only the function to compress it to Zip came out. ~~ In the comments, I told you that you can use array_map (). Thank you, knoguchi!
So I wrote it (although it's the same code as the comment).
array_map
$x = [1,2,3];
$y = [4,5,6];
$set = array_map(NULL, $x, $y);
var_dump($set);
/*
array(3) {
[0]=>
array(2) {
[0]=>
int(1)
[1]=>
int(4)
}
[1]=>
array(2) {
[0]=>
int(2)
[1]=>
int(5)
}
[2]=>
array(2) {
[0]=>
int(3)
[1]=>
int(6)
}
}
*/
I haven't mastered PHP yet ...
Recommended Posts