2017-10-24 14 views
-2
words = [ 'look', 'into', 'my', 'eyes', 'look', 'into', 'my', 'eyes', 'the', 'eyes', 'the', 'eyes', 'the', 'eyes', 'not', 'around', 'the', 'eyes',"don't", 'look', 'around', 'the', 'eyes', 'look', 'into', 'my', 'eyes', "you're", 'under'] 

def requirement(word): 
    onelist = [] 
    if word in words: 
     return(len(onelist.append(word))) 


print(map(requirement('look'), words)) 

エラーなぜ "TypeError:型 'NoneType'のオブジェクトにlen()がありませんか?私は "マップ" 機能を練習したい

TypeError: object of type 'NoneType' has no len() 

。しかし、私はlen()を使うと間違いを犯したようです。

+5

のようなものを試してみてくださいあなた' '' len'呼び出しから 'list.append'コールを分離するために定義さonelist'.Youない上、関数' list.append'に 'len'を呼び出して再。 –

+1

@Coal_好奇心の念から、コメントにエンコードされたアポストロフィーはどうでしたか? – Carcigenicate

+1

私は手がかりがない、私はとにかくアプリには、バグかもしれない:) –

答えて

2

機能list.append()は、リストを適切に変更してNoneを返します。したがって、行

return(len(onelist.append(word))) 

の長さを返そうとしています。これは明らかにTypeErrorをスローする必要があります。

onelist.append(word) 
return(len(onelist)) 
関連する問題