함수 zip()


1 JavaScript[ | ]

const a = [1, 2, 3];
const b = ['a', 'b', 'c'];
const out = a.map((x, i) => [x, b[i]]);
console.log( out ); // [ [ 1, 'a' ], [ 2, 'b' ], [ 3, 'c' ] ]
const a = [1, 2, 3];
const b = ['a', 'b', 'c'];
const c = ['one', 'two', 'three'];
const out = a.map((x, i) => [x, b[i], c[i]]);
console.log( out );

2 Python[ | ]

a = [1, 2, 3]
b = ['a', 'b', 'c']
print( zip(a, b) ) # <zip object at 0x7f1a9d087800>
print( list(zip(a, b)) ) # [(1, 'a'), (2, 'b'), (3, 'c')]
a = [1, 2, 3]
b = ['a', 'b', 'c']
c = ['one', 'two', 'three']
print( zip(a, b, c) ) # <zip object at 0x7faad409f980>
print( list(zip(a, b, c)) ) # [(1, 'a', 'one'), (2, 'b', 'two'), (3, 'c', 'three')]

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}