프로그래밍/python
배열에 빈 값 ('')이 있는지 확인 후 그 빈 값 지우기
이휘재123
2023. 3. 15. 16:59
반응형
my_list = ['', 'apple', '', 'banana', 'carrot', '']
# 빈 값이 있는지 확인
if '' in my_list:
# 빈 값들을 제거
my_list = list(filter(lambda x: x != '', my_list))
print(my_list) # ['apple', 'banana', 'carrot']
반응형