zoukankan      html  css  js  c++  java
  • 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 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
  • 相关阅读:
    根据经纬度获取距离
    获取本浏览器经纬度坐标
    仿造mongodb的存储方式存一些假数据
    ty修饰符 public private static
    ty 枚举类型
    限制字符串的选择
    typeScript类型别名
    ty 函数的讲解
    ty数组的讲解
    接口的讲解
  • 原文地址:https://www.cnblogs.com/hzhesi/p/3891486.html
Copyright © 2011-2022 走看看