0
문자열에서 단어를 찾고 역순으로 바꾸려고합니다. 따라서 This 17
이 있으면 sihT 17
을 보내고 싶습니다.문자열을 역순으로 검색하고 바꾸기
하지만 난 당신이 re.sub
내부 기능을 사용할 수 있습니다 re.sub()
import re
pat_word = re.compile("[a-zA-Z]+")
input = raw_input ("Input: ")
match = pat_word.findall(input)
if match:
s = re.sub(pat_word, "reverse", input)
print s
큰 설명을 부탁드립니다. 나는 많이 배웠다! – Saphire
@Saphire 정규 표현식에 그룹이 없습니다. 기본적으로 [group (0)] (http://docs.python.org/2/library/re.html#re.MatchObject.group)는 전체를 반환합니다. 시합. BTW에서는 간단히'pat_word.sub (lambda m : m.group (0) [:: - 1], input)'을 사용할 수 있습니다. –