@@ -6616,37 +6616,38 @@ \section{연습 문제}
66166616\end{exercise}
66176617
66186618
6619- \chapter{Case study: word play}
6619+ \chapter{사례 연구: 단어 놀이}
6620+ %Case study: word play
66206621\label{wordplay}
66216622
6622- This chapter presents the second case study, which involves
6623- solving word puzzles by searching for words that have certain
6624- properties. For example, we'll find the longest palindromes
6625- in English and search for words whose letters appear in
6626- alphabetical order. And I will present another program development
6627- plan: reduction to a previously solved problem.
6623+ 이 번 장에서는 두 번째의 사례 연구를 선보인다. 특정 성질을 갖는
6624+ 단어들을 찾아 단어 퍼즐을 푸는 프로그램이다. 예를 들어 영어에 존재하는
6625+ 긴 회문을 찾아 알파벳 순으로 글자가 나타나는 단어들을 찾을 것이다.
6626+ 그리고 나서 이전에 해결한 문제의 해법을 응용하는 다른 프로그램 개발
6627+ 계획에 대해 설명할 것이다.
66286628
66296629
6630- \section{Reading word lists}
6630+
6631+ \section{단어 목록 읽어 들이기}
6632+ %Reading word lists
66316633\label{wordlist}
66326634
6633- For the exercises in this chapter we need a list of English words.
6634- There are lots of word lists available on the Web, but the one most
6635- suitable for our purpose is one of the word lists collected and
6636- contributed to the public domain by Grady Ward as part of the Moby
6637- lexicon project (see \url{http://wikipedia.org/wiki/Moby_Project}) . It
6638- is a list of 113,809 official crosswords; that is, words that are
6639- considered valid in crossword puzzles and other word games. In the
6640- Moby collection, the filename is {\tt 113809of.fic}; you can download
6641- a copy, with the simpler name {\tt words.txt}, from
6642- \url{http://thinkpython2.com/code/words.txt} .
6635+ 이 장에서의 활용할 예제들은 영어 단어의 목록이 있어야 한다. 웹에는
6636+ 무수히 많은 단어 목록들이 있지만 우리의 목적에 가장 적합한 목록은
6637+ Grady Ward가 공개적으로 유지 관리 및 기여하고 있는 모비 어휘목록
6638+ 프로젝트 (Moby lexicon project,
6639+ \url{http://wikipedia.org/wiki/Moby_Project} 참고)이다 . 이 목록은
6640+ 113,809개의 공식 십자 낱말 풀이용 단어들이다. 십자 낱말 풀이와 다른
6641+ 단어 놀이에 적합한 단어 목록이다. 이 모비 목록은 {\tt
6642+ 113809of.fic}이라는 이름을 갖고 있지만
6643+ \url{http://thinkpython2.com/code/words.txt}에서 {\tt words.txt}라는
6644+ 쉬운 이름으로 내려 받아 사용하면 된다 .
66436645\index{Moby Project}
66446646\index{crosswords}
66456647
6646- This file is in plain text, so you can open it with a text
6647- editor, but you can also read it from Python. The built-in
6648- function {\tt open} takes the name of the file as a parameter
6649- and returns a {\bf file object} you can use to read the file.
6648+ 이 파일은 서식이 없어서 어떤 문서 편집기로 열어도 되지만, Python에서 이
6649+ 파일을 읽어보자. 파일 이름을 매개 변수로 {\tt open}이라는 내장 함수에
6650+ 전달하면 해당 파일을 읽을 수 있는 {\bf 파일 객체}를 리턴 받는다.
66506651\index{open function}
66516652\index{function!open}
66526653\index{plain text}
@@ -6658,34 +6659,33 @@ \section{Reading word lists}
66586659>>> fin = open('words.txt')
66596660\end{verbatim}
66606661%
6661- {\tt fin} is a common name for a file object used for input. The file
6662- object provides several methods for reading, including {\tt readline},
6663- which reads characters from the file until it gets to a newline and
6664- returns the result as a string: \index{readline method}
6662+ {\tt fin}은 입력으로 전달 받은 파일 객체를 나타내는 일반적인 이름이다.
6663+ 파일 객체는 읽기를 위한 여러 메소드를 제공하는데 그 중에는 {\tt
6664+ readline}도 포함된다. 이 메소드는 파일에서 줄 바꿈(newline) 기호를 만나기
6665+ 전까지의 글자들을 읽은 후 해당 문자열을 리턴한다.
6666+ \index{readline method}
66656667\index{method!readline}
66666668
66676669\begin{verbatim}
66686670>>> fin.readline()
66696671'aa\r\n'
66706672\end{verbatim}
66716673%
6672- The first word in this particular list is ``aa'', which is a kind of
6673- lava. The sequence \verb"\r\n" represents two whitespace characters,
6674- a carriage return and a newline, that separate this word from the
6675- next.
6674+ 이 목록에서 첫 번째 단어는 ``aa''로 용암의 일종이다. 그 뒤에 따라오는
6675+ \verb"\r\n"은 두 개의 공백 문자로 리턴(carriage return)과 줄 바꿈을
6676+ 나타내며 다음 단어와 지금의 단어를 구분하는 역할을 한다.
66766677
6677- The file object keeps track of where it is in the file, so
6678- if you call {\tt readline} again, you get the next word:
6678+ 파일 객체는 파일에서의 현재 위치를 기억하고 있기 때문에 또 한 번 {\tt
6679+ readline}을 호출하면 그 다음 단어를 얻는다.
66796680
66806681\begin{verbatim}
66816682>>> fin.readline()
66826683'aah\r\n'
66836684\end{verbatim}
66846685%
6685- The next word is ``aah'', which is a perfectly legitimate
6686- word, so stop looking at me like that.
6687- Or, if it's the whitespace that's bothering you,
6688- we can get rid of it with the string method {\tt strip}:
6686+ 그 다음 단어는 ``aah''이며, 이 단어도 전혀 이상하지 않은 낱말이다.
6687+ 만약 공백 문자가 거슬린다면 {\tt strip}이라는 문자열 메소드를 이용하여
6688+ 없앨 수 있다.
66896689\index{strip method}
66906690\index{method!strip}
66916691
@@ -6696,9 +6696,8 @@ \section{Reading word lists}
66966696'aahed'
66976697\end{verbatim}
66986698%
6699- You can also use a file object as part of a {\tt for} loop.
6700- This program reads {\tt words.txt} and prints each word, one
6701- per line:
6699+ {\tt for} 루프에 파일 객체를 사용할 수도 있다. 다음의 프로그램은 {\tt
6700+ words.txt}를 읽어서 각 단어를 한 줄씩 읽는 동작을 한다.
67026701\index{open function}
67036702\index{function!open}
67046703
@@ -6713,90 +6712,91 @@ \section{Reading word lists}
67136712\section{연습 문제}
67146713%Exercises
67156714
6716- There are solutions to these exercises in the next section.
6717- You should at least attempt each one before you read the solutions .
6715+ 이 연습 문제들에 대한 해답은 다음 절에 나와 있다. 해법을 읽어보기 전에
6716+ 풀어 보기 바란다 .
67186717
6719- \begin{exercise}
6720- Write a program that reads {\tt words.txt} and prints only the
6721- words with more than 20 characters (not counting whitespace) .
6718+ \begin{exercise}
6719+ {\tt words.txt}를 읽는 프로그램을 작성하여 (공백을 포함하지 않고) 20
6720+ 글자 이상이 되는 단어들만 출력 해보자 .
67226721\index{whitespace}
67236722
67246723\end{exercise}
67256724
67266725\begin{exercise}
67276726
6728- In 1939 Ernest Vincent Wright published a 50,000 word novel called
6729- {\em Gadsby} that does not contain the letter ``e''. Since ``e'' is
6730- the most common letter in English, that's not easy to do.
6727+ 1939년에 Ernest Vincent Wright가 {\em Gadsby}라는 50,000 단어로 된
6728+ 소설을 출판하였다. 그 소설에는 영어에서 가장 흔한 글자 중 하나인
6729+ ``e''가 포함되어 있지 않다. 그런 글을 쓴다는 것이 쉬운 일은 아니었을
6730+ 것이다.
6731+
6732+ 사실 이 흔한 글자를 쓰지 않고는 사적인 생각을 하기도 어렵다.
6733+ 처음에는 매우 느리겠지만 조심스럽게 오랜 시간 동안 훈련을 하다보면 할
6734+ 수 있게 된다.
67316735
6732- In fact, it is difficult to construct a solitary thought without using
6733- that most common symbol. It is slow going at first, but with caution
6734- and hours of training you can gradually gain facility.
6736+ 설명은 여기까지.
67356737
6736- All right, I'll stop now.
6738+ \verb"has_no_e"이라는 함수를 작성하여 전달 받은 단어에 ``e''가 없다면
6739+ {\tt True}를 리턴하도록 하자.
67376740
6738- Write a function called \verb"has_no_e" that returns {\tt True} if
6739- the given word doesn't have the letter ``e'' in it.
6741+ 이전 절에서 사용한 프로그램을 수정하여 ``e''를 포함하고 있지 않은
6742+ 단어들만 출력하도록 한 뒤 단어 목록에서 ``e''를 포함하고 있지 않은
6743+ 단어의 백분율을 계산해보자.
67406744
6741- Modify your program from the previous section to print only the words
6742- that have no ``e'' and compute the percentage of the words in the list
6743- that have no ``e''.
67446745\index{lipogram}
67456746
67466747\end{exercise}
67476748
67486749
67496750\begin{exercise}
67506751
6751- Write a function named {\tt avoids}
6752- that takes a word and a string of forbidden letters, and
6753- that returns {\tt True} if the word doesn't use any of the forbidden
6754- letters.
6752+ 단어와 금지 문자열을 입력 받는 {\tt avoids}라는 함수를 작성해보자.
6753+ 만약 이 함수가 {\tt True}를 리턴하면 해당 단어는 금지 문자열을 쓰고
6754+ 있지 않다는 뜻이다.
67556755
6756- Modify your program to prompt the user to enter a string
6757- of forbidden letters and then print the number of words that
6758- don't contain any of them.
6759- Can you find a combination of 5 forbidden letters that
6760- excludes the smallest number of words?
6756+ 사용자가 금지 문자를 입력하도록 프로그램을 수정한 후 금지 문자열을
6757+ 포함하지 않는 단어가 총 몇 개인지 출력하도록 해보자. 가장 적은 수의
6758+ 단어들을 목록에서 제거하도록 문자 다섯 개로 이루어진 금지 문자 집합을
6759+ 구성할 수 있겠는가?
67616760
67626761\end{exercise}
67636762
67646763
67656764
67666765\begin{exercise}
67676766
6768- Write a function named \verb"uses_only" that takes a word and a
6769- string of letters, and that returns {\tt True} if the word contains
6770- only letters in the list. Can you make a sentence using only the
6771- letters {\tt acefhlo}? Other than ``Hoe alfalfa?''
6767+ 단어와 문자열을 입력 받는 \verb"uses_only" 라는 함수를 작성하여
6768+ 전달한 문자열로만 이루어진 단어인 경우에만 {\tt True}를 리턴하도록
6769+ 해보자. {\tt acefhlo}만으로 로 이루어진 문장을 만들 수 있겠는가?
6770+ ``Hoe alfalfa''외에 다른 문장을 만들어보자.
67726771
67736772\end{exercise}
67746773
67756774
67766775\begin{exercise}
67776776
6778- Write a function named \verb"uses_all" that takes a word and a
6779- string of required letters, and that returns {\tt True} if the word
6780- uses all the required letters at least once. How many words are there
6781- that use all the vowels {\tt aeiou}? How about {\tt aeiouy}?
6777+ 단어와 꼭 사용해야 하는 글자로 이루어진 문자열을 입력 받는
6778+ \verb"uses_all" 라는 함수를 작성해보자. 이 함수는 꼭 사용해야 하는
6779+ 문자열의 글자들을 최소한 한 번 사용하면 {\tt True}를 리턴한다. {\tt
6780+ aeiou}를 모두 사용하는 단어는 몇 개나 있는가? {\tt aeiouy}를
6781+ 사용하는 하는 단어는 몇 개나 있나?
67826782
67836783\end{exercise}
67846784
67856785
67866786\begin{exercise}
67876787
6788- Write a function called \verb"is_abecedarian" that returns
6789- {\tt True} if the letters in a word appear in alphabetical order
6790- (double letters are ok).
6791- How many abecedarian words are there?
6788+ 단어의 글자들이 알파벳 순으로 나열이 되어 있으면 {\tt True}를
6789+ 리턴하는 \verb"is_abecedarian"이라는 함수를 작성해보자(두 번 연속
6790+ 사용되는 경우도 인정된다). 알파벳 순으로 된 단어가 몇 개나 되는가?
67926791
67936792\index{abecedarian}
67946793
67956794\end{exercise}
67966795
67976796
67986797
6799- \section{Search}
6798+ \section{검색}
6799+ %Search
68006800\label{search}
68016801\index{search pattern}
68026802\index{pattern!search}
0 commit comments