The end of other
The end of other
For language training our Robots want to learn about suffixes.
In this task, you are given a set of words in lower case. Check whether there is a pair of words, such that one word is the end of another (a suffix of another). For example: {"hi", "hello", "lo"} -- "lo" is the end of "hello", so the result is True.
Hints: For this task you should know how to iterate through set types and string data type functions. Read more about set type hereand string functions here.
Input: Words as a set of strings.
Output: True or False, as a boolean.
题目大义:给出一个含有单词的集合(set),如果某个单词是另一个单词的后缀,如"lo"是"hello"的后缀,则返回True,如果不存在则返回False。
一开始认为set可以使用index,就像数组般使用,可惜了,set并不支持。想想也合理,c++中的set也是不支持[]索引的,于是乎想到了for xx in xx形式,加上提示:str.endswith(suffix[, start[, end]]),恍然大悟,给出拙劣的Python代码
1 def checkio(words_set):
2 for words in words_set:
3 for other_words in words_set:
4 if other_words != words and other_words.endswith(words):
5 return True
6
7 return False
随机推荐
- Maven, IntellJ Idea 配置注意点
1. Maven要自己安装一个: 2. Maven设置中,settings.xml和repository地址都配置成自己: 3. Enable Auto import 4. 找不到jar文件时,自己的 ...
- 九度OJ 1437 To Fill or Not to Fill
题目大意:小明从杭州去往某目的地,要经过一些加油站,每个加油站的价格不一样.若能顺利到达,求加油费用最少为多少,否则求出能行驶的最远距离. 思路:贪心算法 1>若下一加油站的价格更便宜,则只需走 ...
- WPF多线程问题
最近碰到这种多线程问题都是在WPF项目中. 1. 问题是这样.有个一主界面线程,然后background线程启动,这个background线程试图去修改主界面里面的数据. 造成死锁. 调用过程,主界面 ...
- Struts2中将.action改为.do
struts2中action的默认拓展名是".action",而之前的拓展名一直为".do",工作中需要要把struts2的action拓展名改为". ...
- C++简介
本文仅用于学习交流,转载请注明:http://www.cnblogs.com/mxbs/p/6266466.html Hello,C++ World! 简介: C++融合了3中不同的编程传统:C语言 ...
- struts配置,略记
<!-- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener ...
- 自己意淫的一个简陋的Python网站扫描器
使用的模块 threading.optparse.urllib2 本地需要放字典,名字需大写. 上代码 def request(url,pathName): try: import urllib2 p ...
- [原创作品]手把手教你怎么写jQuery插件
这次随笔,向大家介绍如何编写jQuery插件.啰嗦一下,很希望各位IT界的‘攻城狮’们能和大家一起分享,一起成长.点击左边我头像下边的“加入qq群”,一起分享,一起交流,当然,可以一起吹水.哈,不废话 ...
- 关于SVN版本控制器的问题与解决方法
1.SVN Working copy is too old 有个.svn的文件夹,去掉在commit试试! 2.中文字符变乱码 尽量不要用中文命名文件,因为很多软件对中文的支持还是有不好的地方.
- python应用之文件属性浏览
import time,os def showFilePROPERTIES(path): for root,dirs,files in os.walk(path,True): print('位置:' ...