強弱と高低

Python3をメインに

CheckiO The end of other

自分の解答

def checkio(words_set):
    counter=0
    for i in sorted(words_set):
        for j in sorted(words_set):
            if i.endswith(j) and i!=j:
                counter+=1
            else:
                pass
    if counter>=1:
        return True
    else:
        return False

プロの解答

def checkio(words):
    """
    You can iterate throught set.
    """
    for w1 in words:
        for w2 in words:
            if w1 != w2 and (w1.endswith(w2) or w2.endswith(w1)):
                return True
    return False

振り返り

endswith()を見つけられたのは良かった。in演算子とかfind()とかも見たけれどバッチリのがあって助かった(?)
美しくないとかわかっていたけれど、counter変数を用意してしまった。orでj.endswith(i)i.endswith(j)を結べばよかったのだな。

使ったメソッド

str.endswith(suffix[, start[, end]])
文字列が指定された suffix で終わるなら True を、そうでなければ False を返します。 suffix は見つけたい複数の接尾語のタプルでも構いません。オプションの start があれば、その位置から判定を始めます。オプションの end があれば、その位置で比較を止めます。 (http://docs.python.jp/3/library/stdtypes.html?highlight=find#str.endswith)