File tree Expand file tree Collapse file tree 3 files changed +110
-0
lines changed
Expand file tree Collapse file tree 3 files changed +110
-0
lines changed Original file line number Diff line number Diff line change 1+ # 14. 문자열 다루기 기본
2+
3+ def solution (s ):
4+ answer = True
5+
6+ if len (s ) == 4 or len (s ) == 6 :
7+ for i in s :
8+ if i .isdigit ():
9+ answer = True
10+ else :
11+ answer = False
12+ break
13+ else :
14+ answer = False
15+
16+
17+ return answer
18+
19+ s_1 = 'a234'
20+ s_2 = '1234'
21+
22+ # print(solution(s_1))
23+ # print(solution(s_2))
24+
25+ def solution_best (s ):
26+ answer = s .isdigit () and len (s ) in (4 , 6 )
27+
28+ return answer
29+
30+ # print(solution_best(s_1))
31+ # print(solution_best(s_2))
32+
33+ import re
34+
35+ def solution_re (s ):
36+ answer = bool (re .match ('^(\d{4}|\d{6}$)' , s ))
37+
38+ return answer
39+
40+ # print(solution_re(s_1))
41+ # print(solution_re(s_2))
Original file line number Diff line number Diff line change 1+ # 16. 문자열 내 마음대로 정렬하기
2+
3+ # 내가 풀지 못했음... 왜 어렵게 생각했을까 ㅠㅠㅠ
4+ def solution (strings , n ):
5+ answer = []
6+
7+ for i in range (len (strings )):
8+ strings [i ] = strings [i ][n ] + strings [i ]
9+
10+ # print(strings)
11+ strings .sort ()
12+ print (strings )
13+
14+ for i in range (len (strings )):
15+ answer .append (strings [i ][1 :])
16+ return answer
17+
18+ strings_1 = ['sun' , 'bed' , 'car' ]
19+ strings_2 = ['abce' , 'abcd' , 'cdx' ]
20+
21+ n_1 = 1
22+ n_2 = 2
23+
24+ # print(solution(strings_1, n_1))
25+ # print(solution(strings_2, n_2))
26+
27+ def solution_best (strings , n ):
28+ answer = sorted (sorted (strings ), key = lambda x : x [n ])
29+
30+ return answer
31+
32+ print (solution_best (strings_1 , n_1 ))
33+ print (solution_best (strings_2 , n_2 ))
Original file line number Diff line number Diff line change 1+ # 8. 문자열 내 p와 y의 개수
2+
3+ def solution (s ):
4+ answer = True
5+
6+ # p와 y 세는 변수 선언
7+ p_cnt = 0
8+ y_cnt = 0
9+
10+ # 반복문 돌면서 개수 세기
11+ for i in s :
12+ if i == 'p' or i == 'p' .upper ():
13+ p_cnt += 1
14+ elif i == 'y' or i == 'y' .upper ():
15+ y_cnt += 1
16+ else :
17+ continue
18+
19+ if p_cnt == y_cnt :
20+ answer = True
21+ else :
22+ answer = False
23+
24+ return answer
25+
26+ s_1 = 'pPoooyY'
27+ s_2 = 'Pyy'
28+
29+ print (solution (s_1 ))
30+ print (solution (s_2 ))
31+
32+ def solution_best (s ):
33+ return s .lower ().count ('p' ) == s .lower ().count ('y' )
34+
35+ print (solution_best (s_1 ))
36+ print (solution_best (s_2 ))
You can’t perform that action at this time.
0 commit comments