CS 간단정리 - [1] 객체지향프로그래밍 (OOP)
: 문자열 리스트를 입력받아서 단어별 빈도수를 측정
ex )
![]()
def count_words(line_list):
word_dict = dict()
for line in line_list:
word_list = line.split()
for word in word_list:
if word_dict.get(word, None) is not None:
word_dict[word] += 1
else :
word_dict[word] = 1
return word_dict
def test():
line_list = []
while True:
line = input("input line (quit : -1) : ")
if line == "-1":
break
line_list.append(line)
print(count_words(line_list))
test()
: 알파벳 문자열을 입력받아 알파벳 순서대로 정렬
- 소문자는 대문자로 변경
- 숫자는 총합을 정렬된 문자열 마지막에 배치
ex )
![]()
def sort_char(word):
total_num = 0
result_list = []
for char in word:
ascii = ord(char)
if ascii >= 48 and ascii < 58:
total_num += int(char)
elif ascii >= 97 and ascii < 97 + 26:
ascii += -32
result_list.append(chr(ascii))
elif ascii >= 65 and ascii < 65 + 26:
result_list.append(char)
result_list.sort()
result_word = ""
for char in result_list:
result_word += char
result_word += str(total_num)
return result_word
def test():
word = input("input word : ")
print(sort_char(word))
test()
: 팀원들이 작성한 코드의 PR 검토 및 comment, approve 작성
ex)
![]()