끄적거림

[문자열 다루기] 긴 공백을 하나의 공백으로 바꾸기 in python 본문

Python/Data Handling

[문자열 다루기] 긴 공백을 하나의 공백으로 바꾸기 in python

Signing 2020. 12. 7. 15:57
728x90
반응형

[문자열 다루기] 문자(한글, 영문)와 숫자만 남기고 특수문자 제거하기 in python

 

[문자열 다루기] 문자(한글, 영문)와 숫자만 남기고 특수문자 제거하기 in python

문자열 핸들링 중에서 특수문자를 제거하는 것을 원하는 경우가 종종 발생한다. 이 코드가 도움이 되길 바란다. 단일변수일 때 import re string = "abcdefㄱㄴㄷㄹㅁㅂ가나다라마바사12345[]{}().,!?'`~;:"

signing.tistory.com

 


지난번 포스팅에서는 문자와 숫자만 추출하는 핸들링을 살펴보았는데, 이번엔 multi space 를 single space로 바꿔보는 핸들링이다.

 

mystring = 'hello,      my name is           MIKE'

' '.join(mystring.split())

# 'hello, my name is MIKE'

 

참고: stackoverflow.com/questions/2077897/substitute-multiple-whitespace-with-single-whitespace-in-python

 

Substitute multiple whitespace with single whitespace in Python

I have this string: mystring = 'Here is some text I wrote ' How can I substitute the double, triple (...) whitespace chracters with a single space, so that I get: mystring = 'Here is...

stackoverflow.com

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형
Comments