"함수 zip()"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 6개는 보이지 않습니다)
3번째 줄: 3번째 줄:
==JavaScript==
==JavaScript==
[[분류: JavaScript]]
[[분류: JavaScript]]
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript' run>
var a = [1, 2, 3];
const a = [1, 2, 3];
var b = ['a', 'b', 'c'];
const b = ['a', 'b', 'c'];
var c = a.map(function (e, i) { return [a[i], b[i]]; });
const out = a.map((x, i) => [x, b[i]]);
console.log( c );
console.log( out ); // [ [ 1, 'a' ], [ 2, 'b' ], [ 3, 'c' ] ]
// [ [ 1, 'a' ], [ 2, 'b' ], [ 3, 'c' ] ]
</syntaxhighlight>
</source>
<syntaxhighlight lang='JavaScript' run>
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 );
</syntaxhighlight>


==Python==
==Python==
[[분류: Python]]
[[분류: Python]]
<source lang='Python'>
<syntaxhighlight lang='Python' run>
a = [1, 2, 3]
a = [1, 2, 3]
b = ['a', 'b', 'c']
b = ['a', 'b', 'c']
print( zip(a, b) )
print( zip(a, b) ) # <zip object at 0x7f1a9d087800>
# [(1, 'a'), (2, 'b'), (3, 'c')]
print( list(zip(a, b)) ) # [(1, 'a'), (2, 'b'), (3, 'c')]
</source>
</syntaxhighlight>
<source lang='Python'>
<syntaxhighlight lang='Python' run>
a = [1, 2, 3]
a = [1, 2, 3]
b = ['a', 'b', 'c']
b = ['a', 'b', 'c']
c = ['one', 'two', 'three']
c = ['one', 'two', 'three']
print( zip(a, b, c) )
print( zip(a, b, c) ) # <zip object at 0x7faad409f980>
# [(1, 'a', 'one'), (2, 'b', 'two'), (3, 'c', 'three')]
print( list(zip(a, b, c)) ) # [(1, 'a', 'one'), (2, 'b', 'two'), (3, 'c', 'three')]
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[함수 array_combine()]]
* [[함수 array_combine()]]

2022년 4월 19일 (화) 11:35 기준 최신판


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 }}