我需要调用我已经创建的各种不同的函数来实现下面的问题。我真的不确定该如何规划才能实现它。问题是。。在
在word list(str,str list)中查找两个单词的anagrams,其中输入参数应该
是一个字符串和一个字符串列表。输出应该是由两个字符串组成的所有字符串的列表
用空格隔开的单词,这样这两个单词都在str列表和组合中
这两个词中有一个str的变音
我期望的输出是:
wordlist = ('and','band','nor,'born')
find_two_word_anagrams_in_wordlist( "brandon", wordlist )
[’and born’, ’band nor’]
如何做到这一点:
- 初始化一个list两个单词的anagrams到空列表[]。在
- 调用find partial anagrams in word list获取所有
可以在单词列表中找到str的部分换位符。在
- 然后,做一个循环,遍历所有这些部分变音图。为每一个
部分anagram part anag执行以下操作:
- 从输入字符串str中删除部分anag的字母以获取
一个字符串,rem,它是去掉
偏字谜
- 调用find anagrams in word list on rem(和输入单词列表)到
得到一个剩余字母的字谜列表
- 对于剩余字母的每个换位符rem anag,形成字符串
part anag+“”+rem anag并将其添加到列表中的两个单词anagrams。在
- 在这一点上,列表中的两个单词应该同时包含这两个单词
其中有一个单词,所以从函数中返回该列表。在
我已经创建的代码是:
^{pr2}$
任何一步一步的帮助或输入将不胜感激。在
Tags:
你有两个选择,你可以用两个不同的单词组合来查看字谜,或者你可以用两个组合来查看所有的字谜。在
你的选择权在这里,我已经实现了两者
这是一些测试
^{pr2}$产生以下输出
你写的
请注意
sorted(w1)==sorted(w2)
就是你所需要的,但是找到一个部分换位符的故事要复杂得多。。。在后脚本
仔细看看丹尼尔对我之前的回答的评论,里面有很多。。。在
相关问题 更多 >
编程相关推荐