如何遍历列表查找某个长度的单词?

Bob*_*Bob 0 python

以列表为例,

F=['MIKE', 'BALL', 'FISH', 'BAT', 'BEAR', 'CAT', 'AT', 'ALLY']
Run Code Online (Sandbox Code Playgroud)

如何通过所述列表迭代查找用户输入的具有一定长度的所有单词?我以为会......

number=input("How long would you like your word to be?")
possible_words=[]
for word in F:
     if word(len)=number:
          possible_words+=word 
Run Code Online (Sandbox Code Playgroud)

mgi*_*son 5

这将给你一个list长度为的单词N

possible_words = [x for x in F if len(x) == N]
Run Code Online (Sandbox Code Playgroud)

请注意,您有list一个字典而不是字典