수업 과제(?) 제출
131
작성한 질문수 4
import string
with open("i_have_a_dream.txt", "r") as my_file:
contents = my_file.read() # 파일 읽기
contents = contents.lower() # 소문자로 변환
remove_this_set = set(string.punctuation) # 문장부호 집합
contents = ''.join([ch for ch in contents if ch not in remove_this_set]) # 문장부호 삭제
word_list = list(set(contents.lower().split())) # 단어 리스트 추출
line_list = contents.splitlines() # 줄 리스트 추출
line_list = [line for line in line_list if line is not ''] # 빈 줄 삭제
print("Total Number of Characters :", len(contents))
print("Total Number of Words:", len(word_list))
print("Total Number of Lines :", len(line_list))
# before
# Total Number of Characters : 9198
# Total Number of Words: 1656
# Total Number of Lines : 87
# after
# Total Number of Characters : 8991
# Total Number of Words: 536
# Total Number of Lines : 44
제출한 코드 (아래)를
''.join([ch for ch in contents if ch not in remove_this_set])
이렇게 바꾸어도 잘 동작하더라구요
''.join(ch for ch in contents if ch not in remove_this_set)
이게 generator랑 iteration과 관련이 있나요?
참조:
stackoverflows 질문&답변
python3 docs의 str.strip()
python3 docs의 str.punctuation()
답변 0
atom warning 글
0
337
0
backend.ai 설치 오류
0
315
0
backend.ai 설치 시 에러 발생
0
740
1
과제 제출 시 hash key is already used 문제 발생
0
445
0
install.bat 오류
0
478
0
과제 제출 시 hash key is already used. 해시키 문제 문의 드립니다.
0
308
1
"Hash key is already used."으로 인한 과제 제출 실패 문의
0
303
1
과제 제출 시 에러가 발생합니다
0
271
1
인트로 강의가 없습니다
0
180
0
사진 링크가 깨져있습니다
0
270
0
slack아직 사용할 수 있는건가요?
0
173
0
강의자료
0
398
4
'backend.ai'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는 배치 파일이 아닙니다.
0
438
2
에러확인부탁드립니다.
0
258
1
number of cases 코드 질문
0
206
1
split 관련 질문입니다!
0
229
1
함수 definition 관련 질문입니다.
0
296
1
is_digit 함수 구현
0
306
1
Map & Reduce 강의 8분 15초
1
233
1
keyword parameter
0
239
1
submit.bat 오류
0
196
2
matrix_transpose 결과값이 뭐죠?
0
176
0
value를 넣으면 key를 반환하는 함수
0
131
0
첨부파일의 unit test는 어떻게 사용하나요?
0
267
0





