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. [转]一步步搭建Ubuntu环境——dpkg 被中断,您必须手工运行 sudo dpkg --configure -a 解决此问题——安装Flashplayer出错 ------不错

    原文网址:http://blog.csdn.net/xuezhimeng2010/article/details/8545261 解决方法如下: sudo rm /var/cache/apt/arch ...

  2. MVC中使用EF(2):实现基本的CRUD功能

    MVC中使用EF(2):实现基本的CRUD功能 By  Tom Dykstra |July 30, 2013 Translated by litdwg   Contoso University示例网站 ...

  3. Team Queue(多队列技巧处理)

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. ASP.NET 实现PDF文件下载

    本文介绍了一种在ASP.NET中下载文件的方法. 方法一:可能是最简单的.最短的方式: Response.ContentType = "application/pdf"; Resp ...

  5. 解决Fetching android sdk component information加载过久问题

    安装完成后,如果直接启动,Android Studio会去获取 android sdk 组件信息,这个过程相当慢,还经常加载失败,导致Android Studio启动不起开.解决办法就是不去获取and ...

  6. Stm32高级定时器(一)

    Stm32高级定时器(一) 1 定时器的用途 2 高级定时器框图 3 时基单元 4 通道 1 定时器的用途 已知一个波形求另一个未知波形(信号长度和占空比) 已知波形的信号长度和占空比产生一个相应的波 ...

  7. windows系统还原

    windows系统还原 windows 系统还原有两种方法: 方法一.开始-控制面板-系统和安全-备份和还原 (或者开始—所有程序—附件—系统工具—系统还原) 详细请看下面的截图说明 方法二.开机的时 ...

  8. AngularJS初步

    AngularJS特点 遵循AMD规范 不需要操作节点 对于jquery,一般是利用现有完整的DOM,然后在这戏Dom的基础上进行二次调教了:而对于AngularJS等框架则是根据数据模型以及其对应用 ...

  9. Android异步请求

    class MyTask_SendMessage extends AsyncTask<String, Void, String> { @Override protected void on ...

  10. Oracle instr 及 like

    原文: http://www.cnblogs.com/crazyjava/archive/2012/10/31/2748202.html instr(string1,string2[,start_po ...