字典翻译 问答 小学 英语 pythonmap和reduce的用法
问题标题:
pythonmap和reduce的用法
问题描述:

pythonmap和reduce的用法

饶伏波回答:
  map(function,sequence[,sequence,...])->list   Returnalistoftheresultsofapplyingthefunctiontotheitemsof   theargumentsequence(s).Ifmorethanonesequenceisgiven,the   functioniscalledwithanargumentlistconsistingofthecorresponding   itemofeachsequence,substitutingNoneformissingvalueswhennotall   sequenceshavethesamelength.IfthefunctionisNone,returnalistof   theitemsofthesequence(oralistoftuplesifmorethanonesequence).   reduce(...)   reduce(function,sequence[,initial])->value   Applyafunctionoftwoargumentscumulativelytotheitemsofasequence,   fromlefttoright,soastoreducethesequencetoasinglevalue.   Forexample,reduce(lambdax,y:x+y,[1,2,3,4,5])calculates   ((((1+2)+3)+4)+5).Ifinitialispresent,itisplacedbeforetheitems   ofthesequenceinthecalculation,andservesasadefaultwhenthe   sequenceisempty.
点击显示
英语推荐
热门英语推荐
  • 语文
  • 数学
  • 英语
  • 科学
  • 作文