python 문자열 찾기, list 의 각 요소에 특정 문자열이 포함된 요소 검색
페이지 정보
본문
## 출처 : https://stackoverflow.com/questions/4843158/check-if-a-python-list-item-contains-a-string-inside-another-string
If you only want to check for the presence of abc in any string in the list, you could try
```
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
if any("abc" in s for s in some_list):
# whatever
```
If you really want to get all the items containing abc, use
```
matching = [s for s in some_list if "abc" in s]
```
## 참고
https://stackoverflow.com/questions/4843158/check-if-a-python-list-item-contains-a-string-inside-another-string
https://hashcode.co.kr/questions/1010/%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84-%EC%A0%80%EC%9E%A5%ED%95%98%EB%8A%94-%EB%A6%AC%EC%8A%A4%ED%8A%B8%EA%B0%80-%ED%8A%B9%EC%A0%95-%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84-%ED%8F%AC%ED%95%A8%ED%95%98%EB%8A%94%EC%A7%80-%EC%95%8C%EC%95%84%EB%82%B4%EB%A0%A4%EA%B3%A0-%ED%95%A9%EB%8B%88%EB%8B%A4
If you only want to check for the presence of abc in any string in the list, you could try
```
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
if any("abc" in s for s in some_list):
# whatever
```
If you really want to get all the items containing abc, use
```
matching = [s for s in some_list if "abc" in s]
```
## 참고
https://stackoverflow.com/questions/4843158/check-if-a-python-list-item-contains-a-string-inside-another-string
https://hashcode.co.kr/questions/1010/%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84-%EC%A0%80%EC%9E%A5%ED%95%98%EB%8A%94-%EB%A6%AC%EC%8A%A4%ED%8A%B8%EA%B0%80-%ED%8A%B9%EC%A0%95-%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84-%ED%8F%AC%ED%95%A8%ED%95%98%EB%8A%94%EC%A7%80-%EC%95%8C%EC%95%84%EB%82%B4%EB%A0%A4%EA%B3%A0-%ED%95%A9%EB%8B%88%EB%8B%A4
추천0
댓글목록
등록된 댓글이 없습니다.