Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
接尾辞のリストがあり、単語がそれらのいずれかで終わっているかどうかを確認したいのですが、印刷したい場合は、次のようにします。
if(string.endswith(any(word in my_list))): print string print" " print word
my_listは、サフィックスのリストです。実行すると、名前「単語」が定義されていないというエラーが表示されます
anyブール値を返します。 str.endswith文字列または文字列のいずれかを期待しtupleます。
any
str.endswith
tuple
あなたはおそらく次のようなものが欲しいでしょう:
if s.endswith(tuple(my_list)): print string
または、実際に一致したものを知りたい場合:
suffix = next((word for word in my_list if s.endswith(word)),False) if suffix: print word, suffix