RubyのinjectとPythonのreduce

RubyのinjectとPythonのreduceは同じようなもの。

Rubyのinject

irb(main):001:0> [1,2,3,4,5].inject{|x,y|x+y}
=> 15

Pythonのreduce

>>> reduce(lambda x,y:x+y,[1,2,3,4,5])
15

((((1+2)+3)+4)+5) という感じに計算される。
Rubyのほうが書きやすいかな。