반응형
Given a string made up of letters a, b, and/or c, switch the position of letters a and b (change a to b and vice versa). Leave any incidence of c untouched.
Example:
'acb' --> 'bca'
'aabacbaa' --> 'bbabcabb'
Solution:
def switcheroo(s):
return s.translate(str.maketrans("ab", "ba"))
def switcheroo(s):
return s.translate({ord('a'): 'b', ord('b'): 'a'})
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1227. CSV representation of array (0) | 2022.12.27 |
---|---|
1226. Alphabet war (0) | 2022.12.27 |
1224. Regex count lowercase letters (0) | 2022.12.25 |
1223. validate code with simple regex (0) | 2022.12.23 |
1222. Formatting decimal places #0 (0) | 2022.12.23 |