我想从单词列表中找到字谜的创建列表.我应该在我的代码或递归中使用另一个循环吗?
some_list = ['bad', 'app', 'sad', 'mad', 'dab','pge', 'bda', 'ppa', 'das', 'dba']
new_list = [some_list[0]]
i = 0
while i+1 < len(some_list):
if (''.join(sorted(some_list[0]))) == (''.join(sorted(some_list[i+1]))):
new_list.append(some_list[i+1])
i = i+1
else:
i = i+1
print(new_list)
Run Code Online (Sandbox Code Playgroud)
['bad', 'dab', 'bda', 'dba'].但我还想要更多其他字谜的列表some_list.我希望输出为: - ['app', 'ppa']
- ['bad', 'dab', 'bda', 'dba']
-['sad', 'das']
word = input("Enter a word: ")
word_length = len(word)
print("The length of", word,"is ", word_length)
Run Code Online (Sandbox Code Playgroud)
如果是'back',则输出为:
The length of back is 4
Run Code Online (Sandbox Code Playgroud)
我希望输出为:
The length of 'back' is 4
Run Code Online (Sandbox Code Playgroud)