[ edit ]

λ式(ラムダ式)

triangle_number = lambda  n: int( n * (n + 1) / 2 )

高階関数reduce()

import functools

def sum_of_range( n ) :
    return( functools.reduce( (lambda x, y: x + y), range( 1, n + 1 ) ) )

import functools
import operator

def sum_of_range( n ) :
    return( functools.reduce( operator.add, range( 1, n + 1 ) ) )

import functools
import operator

sum_of_range = lambda n: functools.reduce( operator.add, range( 1, n + 1 ) )

SoftEng: Python/Prog/Example/02/Ex_003a/AdvancedTopics (last edited 2018-10-28 12:22:59 by TadashiIijima)