출처 : 반크_독도2023
참고풀이1]
s = "You said some winds blow forever and I didn't understand"
list1 = s.split()
remove_words = ['some', 'forever']
print("입력 문자열:")
print(s)
print("삭제 단어들:")
print(remove_words)
print("\n삭제 후 남은 단어들을 문자열로 취합한 내용]")
for word in list1:
if word in remove_words:
list1.remove(word)
#삭제단어들을 제거한 리스트를 다시 문자열로 만든다.
Str=""
for word in list1:
Str += word + " "
print(Str)
참고풀이 결과1]
참고풀이2] join()를 사용한 예
s = "You said some winds blow forever and I didn't understand"
list1 = s.split()
remove_words = ['some', 'forever']
print("입력 문자열:")
print(s)
print("삭제 단어들:")
print(remove_words)
print("\n삭제 후 남은 단어들을 문자열로 취합한 내용]")
for word in list1:
if word in remove_words:
list1.remove(word)
#삭제단어들을 제거한 리스트를 다시 문자열로 만든다.
Str=" ".join(list1)
print(Str)
참고풀이 결과2]
대한민국의 아름다운 영토, 독도의 봄
'프로그램 > Python 1000제' 카테고리의 다른 글
Python 291제] 두근두근 파이썬(개정판) CHAPTER 9 도전문제 p289 (0) | 2024.07.16 |
---|---|
Python 290제] 파이썬 EXPRESS CHAPTER 10. 도전문제 p474 (0) | 2024.07.04 |
Python 288제] 두근두근 파이썬(개정판) CHAPTER 9 도전문제 p279 (0) | 2024.06.28 |
Python 287제] 두근두근 파이썬(개정판) CHAPTER 8 도전문제 p256 (0) | 2024.06.21 |
Python 286제] 파이썬 EXPRESS CHAPTER 10. 도전문제 p472 (0) | 2024.05.30 |
댓글