jgugugiug 发表于 2018-8-15 13:49:50

python reduce分析

def reduc(functon,iterable,initializer=None):  
    it = iter(iterable)
  
    if initializer is None:
  
      try:
  
            initializer = next(it)
  
      except StopIteration:
  
            raise TypeError('reduce of empty')
  
    accum_value = initializer
  
    for x in iterable:
  
      accum_value = functon(accum_value, x)
  
    return accum_value
页: [1]
查看完整版本: python reduce分析