The end of other

來源:互聯網
上載者:User

標籤:des   blog   http   使用   io   strong   for   art   

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 True6     7     return False

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.