
https://school.programmers.co.kr/learn/courses/30/lessons/12915
def solution(strings, n):
strings.sort()
return sorted(strings, key = lambda x: x[n])
https://school.programmers.co.kr/learn/courses/30/lessons/12916?language=python3
def solution(s):
s = list(s.lower())
pcnt = len(list(filter(lambda x : x == "p", s)))
ycnt = len(list(filter(lambda x : x == "y", s)))
if pcnt == ycnt:
return True
else:
return False
def solution(s):
return s.lower().count('p') == s.lower().count('y')
https://school.programmers.co.kr/learn/courses/30/lessons/12917
ord(a) : 65
chr(65) : aa1 = [6, 3, 9]
print('a1:', a1)
a1.sort(reverse=True) # 원본을 역정렬하고 수정합니다(in-place)
print('-----수행 후-----')
print('a1:', a1)
# a1: [9, 6, 3]
s = "abcd"
s.sort() '''=> Error, string은 iterator가 아니기에 sort 속성이 없음.'''
'''반대로 sorted 는 알아서 list로 만든 다음 reverse 한다.'''
s = sorted(s, reverse=True)
#-> ["d", "c", "b", "a"]
from functools import reduce
def solution(s):
#ord -> sort -> chr -> connect
answer = ''
s = list(map(lambda x : ord(x), list(s)))
s.sort(reverse=True)
answer = list(map(lambda x : chr(x), s))
return reduce(lambda x, y: x + y, answer)
=> 우선 아스키로 바꾼 다음 sorting하고 다시 char로 바꾼 실행절차로 하니
딱봐도 코드가 복잡해보임.
def solution(s):
return ''.join(sorted(s, reverse=True))
sorted로 문자열 자체를 list로 만들어 reverse정렬 후 join 시킨 것.
애초에 sort속성이 사전순 정렬이므로 ord, chr이 필요하지 않다.