The end of other

时间:2023-03-09 01:32:04
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. 转:Android 测试 Appium、Robotium、monkey等框架或者工具对比

    原文地址:http://demo.netfoucs.com/u012565107/article/details/36419297# 1. Appium测试 (功能测试,用户接受度测试,黑盒测试) - ...

  2. 推荐2个小工具 .NET reflector resharper

  3. hdu4623:crime 数学优化dp

    鞍山热身赛的题,也是去年多校原题 题目大意: 求n个数的排列中满足相邻两个数互质的排列的数量并取模 当时的思路就是状压dp.. dp[i][state]  state用二进制记录某个数是否被取走,i ...

  4. 符号表实现(Symbol Table Implementations)

    符号表的实现有很多方式,下面介绍其中的几种. 乱序(未排序)数组实现 这种情况,不需要改变数组,操作就在这个数组上执行.在最坏的情况下插入,搜索,删除时间复杂度为O(n). 有序(已排序)数组实现 这 ...

  5. phpcms:四、尾部包含

    四.尾部包含1.包含尾部文件:{template "content","footer"}2.栏目列表调用(关于我们| 联系方式| 版权声明| 招聘信息|):{p ...

  6. MyEclipse第一个Servlet程序 --解决Win7系统下MyEclipse与Tomcat连接问题

    前言 本文旨在帮助学习java web开发的人员,熟悉环境,在Win7系统下运行自己的第一个Servlet程序,因为有时候配置不当或系统原因可能会运行不成功,这给初学者带来了一定烦恼,我也是为此烦恼过 ...

  7. .net网站开发(一):1.input表单元素

    其实,在半年前我对网站开发还是完全不感冒的,不是没认识,而是只认识到表面.我以为网站模型就那几样,新闻.论坛.博客啥的,仿个站出来有什么意思?但现在我是知道了,大多应用开发还是采用B/S架构的,包括服 ...

  8. 选择Android还是IOS开发?

    选择Android还是IOS? 随着移动互联网的如日中天,涌现了越来越多的开发者.IOS优秀的用户体验,Android极高的用户群,这对于开发者来说陷入了选择困难的境地,尤其是新入门的开发者,精力有限 ...

  9. LoadRunner测试下载功能点脚本(方法二)

    在上一篇<LoadRunner下载功能点脚本(方法一)>中,实现的脚本仅是录制下载功能点的脚本,现在性能需求的场景更改如下: 性能需求:对系统某页面中,点击下载并将下载文件保存到本地电脑的 ...

  10. 基于JQUERY写的 LISTBOX 选择器

    本文来之于:http://blog.****.net/jetsteven/article/details/5104380# 1.经常用到如下图的选择器,而且要支持排序的,所以萌生用JQUERY写一个. ...