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

随机推荐

  1. jquery 图片轮播demo实现

    转载注明出处!!! 转载注明出处!!! 转载注明出处!!! 图片轮播demo,弄清楚过程其实是一个很简单的东西,看网上都没有什么实质性的代码,就自己把过程捋了一遍实现了. 这次因为随手写的,所以没有做 ...

  2. [Unity] 3D数学基础 - 2D旋转矩阵

    2D矩阵的旋转: NewX = X * Cos(α) - Y * Sin(α) NewY = X * Sin(α) + Y * Cos(α) 一般在三角函数中使用的是弧度,我们可以通过下面的公式将角度 ...

  3. 六大免费网站数据采集器对比(火车头,海纳,云采集,ET,三人行,狂人采集)

    2013年02月27日 PHP开源系统 暂无评论 阅读 497 views 次 在目前的站长圈内,比较流行的采集工具有很多,但是总结起来,比较出名的免费的就这么几个:火车头,海纳,云采集,ET,三人行 ...

  4. HDU 1160 FatMouse's Speed(DP)

    点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...

  5. C++:普通变量C++命名规则

    C++提倡使用拥有一定意义的变量名,使程序代码更有阅读性,命名是必须使用的几种简单的C++命名规则: 命名时只能使用:字母字符.数字和下划线(_); 第一个字符不能是数字: 区分大小写(C++对大小写 ...

  6. Linux系统网络编程中TCP通讯socket--send导致进程被关闭

    https://blog.csdn.net/dsanmux/article/details/52083403 https://blog.csdn.net/u011425939/article/deta ...

  7. centos7 64运行32位程序

    yum在线安装: sudo yum install xulrunner.i686 或者: sudo yum install ia32-libs.i686 PS:可以查看一下当前源库里有没有ia32-l ...

  8. Java提高篇(二):IO字节流、字符流和处理流

    在我们的Java语言当中,通常会有对文件进行读写,因此我们引入java的IO类来进行文件的读写. 一.字节流 下面是一个字节流的实例: import java.io.*; public class I ...

  9. ELK的高级篇(测试记录各种日志)

    一.elk架构已经完成情况情况下  访问限制: 加个x-pack插件  1)一个脚本收集多个日志,if 判断写入es的索引 [root@k8s6 conf.d]# cat file.conf inpu ...

  10. PT与PX区别

    字体大小的设置单位,常用的有2种:px.pt.这两个有什么区别呢? 先搞清基本概念:px就是表示pixel,像素,是屏幕上显示数据的最基本的点: pt就是point,是印刷行业常用单位,等于1/72英 ...

上一篇:hcip第一天


下一篇:数据库----SQL基本查询