-1
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))

Error

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

I want to practise the function "map". But it seems that I made a mistake when I use len().

Van Peer
  • 2,127
  • 2
  • 25
  • 35
YYGX
  • 151
  • 2
  • 8

1 Answers1

2

The function list.append() modifies a list in place and returns None. So the line

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

is trying to return the length of None, which should obviously throw a TypeError. Try something like

onelist.append(word)
return(len(onelist))
wpercy
  • 9,636
  • 4
  • 33
  • 45