在特定条件下从TXT文件中过滤列表
我需要在特定单词上过滤txt文件。以少于10个字母和具有重复字母的字母的字母结尾的单词应从TXT文件中过滤出来。然后,应将它们作为单词和单词数的列表返回。到目前为止我有这个
exclude = 'd'
f = open('nameofthefile.txt', 'r')
I need to filter a txt file on specific words. Words that end with 'd', that are less than 10 letters and words that have duplicate letters should be filtered out from the txt file. Then they should be returned as a list of words and number of words as a pair. So far I have this
exclude = 'd'
f = open('nameofthefile.txt', 'r')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我做的。
我不确定我会理解您所说的一切,但这是我所做的:
namefthefile.txt
:main.py:
您可以像:
如果最后一个字母为: D:
如果单词小于10个字母:
如果该单词没有重复的字母
Here is what I made.
I'm not sure I understood everything you said but here is what I made:
nameofthefile.txt
:main.py:
You can refractor it like:
If the last letter is d:
If the word is less than 10 letters:
If the word doesn't have duplicate letters