Notice
Recent Posts
Recent Comments
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

CHIqueen

[Intro] reverseParenthese 본문

프로그래밍/CodeSignal

[Intro] reverseParenthese

CHIqueen 2020. 3. 11. 14:25
def reverseInParentheses(inputString):
    return eval('"' + inputString.replace('(', '"+("').replace(')', '")[::-1]+"') + '"')

원래는 ( 으로 split해서 )이 있을때 잘라서 [::-1]하고 붙이고 [::-1]하려고 했으나 매우 비효율적이라 생각이 들어서 파이썬만이 할 수 있는 eval을 통해 replace해서 그냥 붙였다.

'프로그래밍 > CodeSignal' 카테고리의 다른 글

[Intro] Add Border  (0) 2020.03.17
[Intro] alternationSums  (0) 2020.03.17
[Intro] Sort by Height  (0) 2020.03.11
[Intro] isLucky  (0) 2020.03.11
[Intro] commonCharacterCount  (0) 2020.03.11
Comments