以列表为例,
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)
这将给你一个list长度为的单词N
possible_words = [x for x in F if len(x) == N]
Run Code Online (Sandbox Code Playgroud)
请注意,您有list一个字典而不是字典
| 归档时间: |
|
| 查看次数: |
1260 次 |
| 最近记录: |