Python - 根据字符串中指定的重复字符查找单词
假设我有一个单词列表: 辞职 树脂 重染 抵抗 我
我还有一个字符串“.10.10”,
需要遍历列表并找到在字符串中有数字的相同位置有重复字符的单词。
例如,字符串“.10.10”会找到单词“redyed”,因为有 1 的地方有 e,有 0 的地方有 d。
另一个字符串“.00.0”。会找到单词“reeded”,因为该位置有 e。
到目前为止,我在 python 中的尝试并不值得打印。目前,我查看字符串,将所有 0 添加到数组中,将 1 添加到数组中,然后尝试查找数组位置中的重复字符。但它非常笨拙并且无法正常工作。
Let's say I have a list of words:
resign
resins
redyed
resist
reeded
I also have a string ".10.10"
I need to iterate through the list and find the words where there are repeated characters in the same locations where there are numbers in the string.
For instance, the string ".10.10" would find the word 'redyed' since there are e's where there are 1's and there are d's where there are 0's.
Another string ".00.0." would find the word 'reeded' as there are e's in that position.
My attempts in python so far are not really worth printing. At the moment I look through the string, add all 0s to an array and the 1s to an array then try to find repeated characters in the array positions. But it's terribly clumsy and doesn't work properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
印刷
prints