文字列内の特定の部分文字列を探したい。文字列は文字列のリストに格納されます。どうすればいいですか?Python string find
2
A
答えて
4
したがって、特定の部分文字列を含む文字列のリスト内のすべての文字列を検索していますか?これは、それを行います。
DATA = ['Hello', 'Python', 'World']
SEARCH_STRING = 'n'
print [s for s in DATA if SEARCH_STRING in s]
# Prints ['Python']
を編集アンドリューの提案で:あなたはそのようlist comprehensionをお読みください「SEARCH_STRING
はどこかに文字列で表示されたリストDATA
内のすべての文字列のリストを作成します。」
+2
+1非常にPythonic!あなたの例を説明するのが最善でしょうが、Pythonの初心者はリストの解説に慣れていないかもしれないからです。 –
0
あなたはそれだけでPythonドキュメント内の検索
関連する問題
- 1. Python string find()メソッド
- 2. Python regex find matches stringの使い方は?
- 3. javascript find string function
- 4. SQL Find String
- 5. std :: string :: findは常にstring :: nposを返します。
- 6. Python Selenium Find Text
- 7. python beautifulsoup findall内find
- 8. Python(Tkinter) - テキストエディタ - Find関数
- 9. Python Web Scraping Unterminated String
- 10. ctypes python std :: string
- 11. Raw String Python Alternative?
- 12. Python String Formatting
- 13. Python String display
- 14. Python 3 String Method?
- 15. Python String Editor
- 16. Python String to float
- 17. Pandas String Replace Python
- 18. C++ std :: string :: findは常にnposを返しますか?
- 19. Python get unicode string size
- 20. PythonのInt to String
- 21. Python Float to String TypeError
- 22. Python M2Crypto load_pub_key from string
- 23. python string replace not working
- 24. Pythonが動作しないfind
- 25. python string find関数がbeautifulsoupから返されたテキストから位置を指定しない
- 26. matlabのfind()をpythonに変換する
- 27. Selenium Python、Find element入力ボックスの問題
- 28. Pythonのshell findコマンドと同等
- 29. 簡単な質問:なぜ文字列ライブラリ関数std :: string :: findは常にstd :: string :: nposを返しますか?
- 30. find()内のMongoose.js find()
例が参考になります、やることは非常に簡単ですhereを見てきました - データがどのように見えるん何を、どのような検索文字列がどのように見えるんし、どのような結果が行いますあなたは欲しいですか? – RichieHindle
なぜこれがダウン表示されますか?あなたたちはばかばかしい! –