함수 reduce()

Jmnote (토론 | 기여)님의 2019년 5월 6일 (월) 03:20 판 (→‎Python)
reduce

1 PHP

$a = [2, 3, 4, 5];
echo array_reduce($a, function($carry, $i) {
    $carry *= $i;
    return $carry;
}, 1);
# 120

2 Python

Python 3
from functools import reduce
a = [2, 3, 4, 5]
print( reduce((lambda x, y: x*y), a) )
# 120

3 같이 보기

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