搜索问题 [英] search problem

查看:81
本文介绍了搜索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

展开 | 选择 | Wrap | 行号

推荐答案

展开 | 选择 | Wrap | 行号



使用re:
Using re:
展开 | 选择 | Wrap | 行号


当我处理一个单词unscrambler时,我遇到了类似的问题。像''anagram'这样的单词会打印3次,因为字母''a''在其中3次。这是使用''set()''解决的。

为了测试你的我把下面的单词放到一个文件中并命名为words.txt:

zygote

anagram

myzygote

zygoter

yourzygote


我从命令行运行它们并获得与zygote相同的结果,但只有一次用字谜。我对我的unscrambler代码进行了一些更改,然后运行代码。它打印出来:

''zygote在字典中''< ----只打印一次


试试下面的代码,它可能有效为了你。您可能需要进行一些更改以容纳您的文件。

I had a similar problem when I was working on a word unscrambler. A word like ''anagram'' would print 3 times because the letter ''a'' is in it 3 times. This was solved using ''set()''.
To test yours I put the following words into a file and named it words.txt:
zygote
anagram
myzygote
zygoter
yourzygote

I ran them from the command line and got the same results as you with zygote, but just once with anagram. I made some changes to my unscrambler code and then ran the code. It prints this:
''zygote is in the dictionary'' <----only prints once

Try the code below, it may work for you. You may have to make a few changes to accomodate your files.

展开 | 选择 | Wrap | 行号


这篇关于搜索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆