List Comprehension
-
[pandas] 검사할 키워드 여러 개 , list + any데이터분석 2023. 3. 21. 11:09
any() : 하나라도 True인게 있으면 True 반환 all() : 모두 True 여야 True 반환 lines_list = ['apple is red', 'banana is yellow', 'cherry is red', 'durian is spiky'] # "red", "banana", or "cherry" 등 제외하고 싶은 리스트로 만들고 exclude_words = ["red", "banana", "cherry"] # lines_list 의 원소인 line에 exclude_words의 원소인 word가 있는지 검사하고 # 하나라도 걸리면 제외시키도록 filtered_lines = [line for line in lines_list if not any(word in line for word in ..