生活随笔
收集整理的這篇文章主要介紹了
                                
把函数作为参数
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
 
                                
                            
                            
                            <python自然語言處理>P164-165
 
 
 
 
# -*- coding:utf-8 -*-
import nltk
sent=['Take','care','of','the','sense',',','and','the','sounds','will','take','care','of','themselves','.']
def extract_property(prop):return [prop(word)for word in sent]
print extract_property(len)#注意,這里的用法是,把len這個(gè)函數(shù)替換上面extract—propterty中的prop,
def last_letter(word):return word[-1]#返回單詞的最后一個(gè)字母
print extract_property(last_letter)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
                            總結(jié)
                            
                                以上是生活随笔為你收集整理的把函数作为参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                            
                                如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。