[ edit ]

高階関数reduce()

import functools

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

import functools
import operator

def sum_of_range( min, max ) :
    return( functools.reduce( operator.add, \
                              range( min, max + 1 ) ) )

import functools
import operator

sum_of_range = \
    lambda min, max: \
        functools.reduce( operator.add, \
                          range( min, max + 1 ) )

SoftEng: Python/Prog/Practice/Basic/02/BP_003a/AdvancedTopics (last edited 2018-10-29 05:13:04 by TadashiIijima)