The end of other
2014-08-05 09:22
423 查看
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 here and 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
相关文章推荐
- SQL Server Error: No Process is on the Other End of the Pipe
- Applications are expected to have a root view controller at the end of application launch
- 还原数据库:The backup set holds a backup of a database other than the existing database
- CRT detected that the application wrote to memory after end of heap buffer.
- [Leetcode] remove nth node from the end of list 删除链表倒数第n各节点
- [Regular Expressions] Find the Start and End of Whole Words
- Following extensions directory contents added to the end of the classpath
- HDU The End of The World【递推】
- Application windows are expected to have a root view controller at the end of application launch
- warning no newline at the end of file
- CRT detected that the application wrote to memory after end of heap buffer
- How to enter an End-Of-File from the keyboard
- The backup set holds a backup of a database other than the existing ‘dbName’ database
- Application windows are expected to have a root view controller at the end of application launch
- ListView数据更新后,自动滚动到底部(聊天时常用)| Listview Scroll to the end of the list after updating the list
- NJUST 1747 Yet another end of the world(13年南京邀请赛-K题-数学)
- iOS 9出现错误Applications are expected to have a root view controller at the end of application launch
- HDU 4596 Yet another end of the world
- Compilation unit name must end with .java, or one of the registered Java-like extensions (a error分析)
- PHP - XML parse error: Extra content at the end of the document