From 95f4a3e2f66074769857a95e3fd9657c647ee19b Mon Sep 17 00:00:00 2001 From: Maruyama Date: Wed, 16 Nov 2016 18:19:43 +0900 Subject: [PATCH 01/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E7=AB=A000.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex00.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 chap_1/ex00.py diff --git a/chap_1/ex00.py b/chap_1/ex00.py new file mode 100644 index 0000000..72d63d2 --- /dev/null +++ b/chap_1/ex00.py @@ -0,0 +1,2 @@ +s="stressed" +print(s[::-1]) From 602dc390fdec40ce8c88c402092da4d8073aa3f4 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Wed, 16 Nov 2016 18:25:47 +0900 Subject: [PATCH 02/23] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex00.py | 1 + 1 file changed, 1 insertion(+) diff --git a/chap_1/ex00.py b/chap_1/ex00.py index 72d63d2..0714d63 100644 --- a/chap_1/ex00.py +++ b/chap_1/ex00.py @@ -1,2 +1,3 @@ +# -*- coding: utf-8 -*- s="stressed" print(s[::-1]) From c113fe433b9fe64ae77f92a4a3291a4c6f3cbb90 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Wed, 16 Nov 2016 19:12:34 +0900 Subject: [PATCH 03/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC1=E7=AB=A001.=E3=81=A7=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex01.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 chap_1/ex01.py diff --git a/chap_1/ex01.py b/chap_1/ex01.py new file mode 100644 index 0000000..24852cf --- /dev/null +++ b/chap_1/ex01.py @@ -0,0 +1,3 @@ +# -*- coding:utf-8 -*- +s="パタトクカシーー" +print(s[::2]) From e3cfd8dfe98ffb9b8e6f86381e2e49994fa01be2 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Wed, 16 Nov 2016 19:48:56 +0900 Subject: [PATCH 04/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC1=E7=AB=A002.=E3=81=A7=E3=81=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex02.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 chap_1/ex02.py diff --git a/chap_1/ex02.py b/chap_1/ex02.py new file mode 100644 index 0000000..2b97535 --- /dev/null +++ b/chap_1/ex02.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +word1="パトカー" +word2="タクシー" + +for(s1,s2) in zip(word1,word2): + print(s1+s2,end="") + From a88b24c1830ba3a9d20cd18694fd18e55c679de4 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Wed, 16 Nov 2016 20:48:41 +0900 Subject: [PATCH 05/23] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex01.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chap_1/ex01.py b/chap_1/ex01.py index 24852cf..d843158 100644 --- a/chap_1/ex01.py +++ b/chap_1/ex01.py @@ -1,3 +1,3 @@ # -*- coding:utf-8 -*- -s="パタトクカシーー" -print(s[::2]) +s = "パタトクカシーー" +print(s[::2]) From c96ba5d9983e56ab56fc3be201fa5ce4479931fd Mon Sep 17 00:00:00 2001 From: Maruyama Date: Wed, 16 Nov 2016 20:49:53 +0900 Subject: [PATCH 06/23] =?UTF-8?q?=E9=80=A3=E7=B5=90=E3=81=97=E3=81=9F?= =?UTF-8?q?=E6=96=87=E5=AD=97=E5=88=97=E3=81=8B=E3=82=89=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex02.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/chap_1/ex02.py b/chap_1/ex02.py index 2b97535..d6004aa 100644 --- a/chap_1/ex02.py +++ b/chap_1/ex02.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- -word1="パトカー" -word2="タクシー" - -for(s1,s2) in zip(word1,word2): - print(s1+s2,end="") +word1 = "パトカー" +word2 = "タクシー" +s = [s1+s2 for s1, s2 in zip(word1, word2)] +print("".join(s)) From 081526385a43988a4af17ecdf3bf168fe5db7f7e Mon Sep 17 00:00:00 2001 From: Maruyama Date: Thu, 17 Nov 2016 18:03:05 +0900 Subject: [PATCH 07/23] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex02.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chap_1/ex02.py b/chap_1/ex02.py index d6004aa..64ab938 100644 --- a/chap_1/ex02.py +++ b/chap_1/ex02.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- +from itertools import chain word1 = "パトカー" word2 = "タクシー" -s = [s1+s2 for s1, s2 in zip(word1, word2)] -print("".join(s)) +merged_word = ''.join(chain(*zip(word1, word2))) +print(merged_word) From 55b924df45e06ea6a99551dbca236beb427833c1 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 10:34:27 +0900 Subject: [PATCH 08/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC1=E7=AB=A003=E3=81=A7=E3=81=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex03.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 chap_1/ex03.py diff --git a/chap_1/ex03.py b/chap_1/ex03.py new file mode 100644 index 0000000..2a0c4bb --- /dev/null +++ b/chap_1/ex03.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +s = """Now I need a drink, alcoholic of course, after the heavy lectures + involving quantum mechanics.""" +s = s.replace(",", "").replace(".", "") +s = s.split(' ') +print(s) + +num = list((len(s[a]) for a in range(15))) +print(num) From c6669d2caf652b5b0cf431e30d718ce2e99536f5 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 11:10:52 +0900 Subject: [PATCH 09/23] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex03.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chap_1/ex03.py b/chap_1/ex03.py index 2a0c4bb..db30aa5 100644 --- a/chap_1/ex03.py +++ b/chap_1/ex03.py @@ -5,5 +5,5 @@ s = s.split(' ') print(s) -num = list((len(s[a]) for a in range(15))) -print(num) +num = [len(s[a]) for a in range(15)] +print(num) \ No newline at end of file From 00e83ca019ea662454c7226dbb672024a4eaeae7 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 14:28:32 +0900 Subject: [PATCH 10/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC1=E7=AB=A004=E3=81=A7=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex04.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 chap_1/ex04.py diff --git a/chap_1/ex04.py b/chap_1/ex04.py new file mode 100644 index 0000000..3013edf --- /dev/null +++ b/chap_1/ex04.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +s = """Hi He Lied because Boron Could Not Oxidize Fluorine. New Nations Might + Also Sign Peace Security Clause. Arthur King Can""" + +s = s.replace(",", "").replace(".", "") +s = s.split(' ') +el = {} + +for index, word in enumerate(s): + if(word == s[0] or word == s[4] or word == s[5] or word == s[6]\ + or word == s[7] or word == s[8] or word == s[14] or word == s[15]\ + or word == s[18]): + el[index+1] = word[0] + else: + el[index+1] = word[0]+word[1] + +print(el) From 9828ec48b90ea47c9967ea422bdc90ef3af847e5 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 14:57:48 +0900 Subject: [PATCH 11/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC1=E7=AB=A005=E3=81=A7=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex05.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 chap_1/ex05.py diff --git a/chap_1/ex05.py b/chap_1/ex05.py new file mode 100644 index 0000000..d194b9a --- /dev/null +++ b/chap_1/ex05.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +def n_gram_word(s, n): + s = s.split(" ") + length = len(s) + return [s[i:i+n] for i in range(0, length, n)] + + +def n_gram_str(s, n): + length = len(s) + return [s[i:i+n] for i in range(0, length, n)] + +s = "I am an NLPer" +n = 2 + +print(n_gram_word(s, n)) +print(n_gram_str(s, n)) From b737e11ea20151b2c1dcd2dacb90ec7017634ec9 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 15:14:24 +0900 Subject: [PATCH 12/23] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex04.py | 6 +++--- chap_1/ex05.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/chap_1/ex04.py b/chap_1/ex04.py index 3013edf..9691b5a 100644 --- a/chap_1/ex04.py +++ b/chap_1/ex04.py @@ -6,10 +6,10 @@ s = s.split(' ') el = {} +indexs = [0, 4, 5, 6, 7, 8, 14 ,15 ,18] + for index, word in enumerate(s): - if(word == s[0] or word == s[4] or word == s[5] or word == s[6]\ - or word == s[7] or word == s[8] or word == s[14] or word == s[15]\ - or word == s[18]): + if index in indexs: el[index+1] = word[0] else: el[index+1] = word[0]+word[1] diff --git a/chap_1/ex05.py b/chap_1/ex05.py index d194b9a..21372ee 100644 --- a/chap_1/ex05.py +++ b/chap_1/ex05.py @@ -1,16 +1,22 @@ # -*- coding: utf-8 -*- def n_gram_word(s, n): s = s.split(" ") - length = len(s) - return [s[i:i+n] for i in range(0, length, n)] + if(n >= len(s)): + return("Can't split") + else: + length = len(s) + return [s[i:i+n] for i in range(0, length, n)] def n_gram_str(s, n): - length = len(s) - return [s[i:i+n] for i in range(0, length, n)] + if(n >= len(s)): + return("Can't split") + else: + length = len(s) + return [s[i:i+n] for i in range(0, length, n)] s = "I am an NLPer" -n = 2 +n = 20 print(n_gram_word(s, n)) print(n_gram_str(s, n)) From 7edae226c0069c398ab3cf0cbda4f33487e1d8b8 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 15:41:37 +0900 Subject: [PATCH 13/23] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex05.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chap_1/ex05.py b/chap_1/ex05.py index 21372ee..ba4616d 100644 --- a/chap_1/ex05.py +++ b/chap_1/ex05.py @@ -16,7 +16,7 @@ def n_gram_str(s, n): return [s[i:i+n] for i in range(0, length, n)] s = "I am an NLPer" -n = 20 +n = 2 print(n_gram_word(s, n)) print(n_gram_str(s, n)) From f488a220fba2f150c0912e95ff2a63e33573f522 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 15:42:16 +0900 Subject: [PATCH 14/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC1=E7=AB=A006=E3=81=A7=E3=81=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex06.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 chap_1/ex06.py diff --git a/chap_1/ex06.py b/chap_1/ex06.py new file mode 100644 index 0000000..a4838bf --- /dev/null +++ b/chap_1/ex06.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +def n_gram_str(s, n): + length = len(s) + return [s[i:i+n] for i in range(0, length, n)] + + +s1 = "paraparaparadise" +s2 = "paragraph" + +X = set(n_gram_str(s1, 2)) +Y = set(n_gram_str(s2, 2)) + +print("X = "+str(X)) +print("Y = "+str(Y)) + +print("intersection = "+str(X.intersection(Y))) +print("union = "+str(X.union(Y))) +print("difference = "+str(X.difference(Y))) + +print("se" in list(X.union(Y))) From 95037267e3e50f16ce87eda5bff057b172f68d57 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 15:49:42 +0900 Subject: [PATCH 15/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC1=E7=AB=A007=E3=81=A7=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex07.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 chap_1/ex07.py diff --git a/chap_1/ex07.py b/chap_1/ex07.py new file mode 100644 index 0000000..0a13f21 --- /dev/null +++ b/chap_1/ex07.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +def weather(x, y, z): + return("{}時の{}は{}".format(x, y, z)) + + +print(weather("12", "気温", "22.4℃")) From 06dd12c13294f2818d3d9dcc3fda035eadb935c6 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 16:36:55 +0900 Subject: [PATCH 16/23] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex05.py | 57 +++++++++++++++++++++++++++++++------------------- chap_1/ex06.py | 8 +++---- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/chap_1/ex05.py b/chap_1/ex05.py index ba4616d..b7e6ce2 100644 --- a/chap_1/ex05.py +++ b/chap_1/ex05.py @@ -1,22 +1,37 @@ # -*- coding: utf-8 -*- -def n_gram_word(s, n): - s = s.split(" ") - if(n >= len(s)): - return("Can't split") - else: - length = len(s) - return [s[i:i+n] for i in range(0, length, n)] - - -def n_gram_str(s, n): - if(n >= len(s)): - return("Can't split") - else: - length = len(s) - return [s[i:i+n] for i in range(0, length, n)] - -s = "I am an NLPer" -n = 2 - -print(n_gram_word(s, n)) -print(n_gram_str(s, n)) +def ngram_str(words, n): + yield from zip(*(words[n:] for n in range(n))) + + +def ngram_word(words, n): + words = words.split(" ") + yield from zip(*(words[n:] for n in range(n))) + + +for num in ngram_str("I am a NLPer", 2): + print(num) + +print("\n") + +for num in ngram_word("I am a NLPer", 2): + print(num) + +#def n_gram_word(s, n): +# s = s.split(" ") +# if(n >= len(s)): +# return("Can't split") +# else: +# length = len(s) +# return [s[i:i+n] for i in range(0, length, n)] +# + +#if n_gram_str(s, n): +# if(n >= len(s)): +# return("Can't split") +# else: +# length = len(s) +# return [s[i:i+n] for i in range(0, length, n)] + + +#print(n_gram_str(s, n)) + diff --git a/chap_1/ex06.py b/chap_1/ex06.py index a4838bf..7068b97 100644 --- a/chap_1/ex06.py +++ b/chap_1/ex06.py @@ -13,8 +13,8 @@ def n_gram_str(s, n): print("X = "+str(X)) print("Y = "+str(Y)) -print("intersection = "+str(X.intersection(Y))) -print("union = "+str(X.union(Y))) -print("difference = "+str(X.difference(Y))) +print("intersection = "+str(X & Y)) +print("union = "+str(X | Y)) +print("difference = "+str(X - Y)) -print("se" in list(X.union(Y))) +print("se" in list(X | Y)) From 91351310a60ac12688ec8627b018263c4465ca3c Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 17:49:25 +0900 Subject: [PATCH 17/23] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex05.py | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/chap_1/ex05.py b/chap_1/ex05.py index b7e6ce2..c5a8519 100644 --- a/chap_1/ex05.py +++ b/chap_1/ex05.py @@ -14,24 +14,4 @@ def ngram_word(words, n): print("\n") for num in ngram_word("I am a NLPer", 2): - print(num) - -#def n_gram_word(s, n): -# s = s.split(" ") -# if(n >= len(s)): -# return("Can't split") -# else: -# length = len(s) -# return [s[i:i+n] for i in range(0, length, n)] -# - -#if n_gram_str(s, n): -# if(n >= len(s)): -# return("Can't split") -# else: -# length = len(s) -# return [s[i:i+n] for i in range(0, length, n)] - - -#print(n_gram_str(s, n)) - + print(num) From db110af5d2fff9c3d0f6ebc05aa8cbe6ffc39f5d Mon Sep 17 00:00:00 2001 From: Maruyama Date: Sat, 19 Nov 2016 17:49:48 +0900 Subject: [PATCH 18/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC1=E7=AB=A008?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex08.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 chap_1/ex08.py diff --git a/chap_1/ex08.py b/chap_1/ex08.py new file mode 100644 index 0000000..0a89b17 --- /dev/null +++ b/chap_1/ex08.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +def cipher(s): + return "".join([chr(219-ord(c)) if c.islower() else c for c in s]) + +sentence = "abCdeFg" +print(cipher(sentence)) +print(cipher(cipher(sentence))) From 085e5f200e7440b123240b46b47579dca6dc7c4a Mon Sep 17 00:00:00 2001 From: Maruyama Date: Mon, 21 Nov 2016 19:30:29 +0900 Subject: [PATCH 19/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC1=E7=AB=A009?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_1/ex09.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 chap_1/ex09.py diff --git a/chap_1/ex09.py b/chap_1/ex09.py new file mode 100644 index 0000000..99bb7a8 --- /dev/null +++ b/chap_1/ex09.py @@ -0,0 +1,18 @@ +# coding: utf-8 +import random + +def rand1(word): + if len(word) <= 4: + return word + m = list(word[1:-1]) + random.shuffle(m) + return word[0] + "".join(m) + word[-1] + + + +sentence = """\ +I couldn't believe that I could actually understand \ +what I was reading : the phenomenal power of the human mind .\ +""" + +print(" ".join(map(rand1, sentence.split()))) From c11d79d502cbf725079d4a20653f7f4bdf8deac5 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Mon, 21 Nov 2016 20:10:03 +0900 Subject: [PATCH 20/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC2=E7=AB=A010?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_2/input.txt | 24 ++++++++++++++++++++++++ chap_2/un10.py | 7 +++++++ 2 files changed, 31 insertions(+) create mode 100644 chap_2/input.txt create mode 100644 chap_2/un10.py diff --git a/chap_2/input.txt b/chap_2/input.txt new file mode 100644 index 0000000..7867f93 --- /dev/null +++ b/chap_2/input.txt @@ -0,0 +1,24 @@ +高知県 江川崎 41 2013-08-12 +埼玉県 熊谷 40.9 2007-08-16 +岐阜県 多治見 40.9 2007-08-16 +山形県 山形 40.8 1933-07-25 +山梨県 甲府 40.7 2013-08-10 +和歌山県 かつらぎ 40.6 1994-08-08 +静岡県 天竜 40.6 1994-08-04 +山梨県 勝沼 40.5 2013-08-10 +埼玉県 越谷 40.4 2007-08-16 +群馬県 館林 40.3 2007-08-16 +群馬県 上里見 40.3 1998-07-04 +愛知県 愛西 40.3 1994-08-05 +千葉県 牛久 40.2 2004-07-20 +静岡県 佐久間 40.2 2001-07-24 +愛媛県 宇和島 40.2 1927-07-22 +山形県 酒田 40.1 1978-08-03 +岐阜県 美濃 40 2007-08-16 +群馬県 前橋 40 2001-07-24 +千葉県 茂原 39.9 2013-08-11 +埼玉県 鳩山 39.9 1997-07-05 +大阪府 豊中 39.9 1994-08-08 +山梨県 大月 39.9 1990-07-19 +山形県 鶴岡 39.9 1978-08-03 +愛知県 名古屋 39.9 1942-08-02 diff --git a/chap_2/un10.py b/chap_2/un10.py new file mode 100644 index 0000000..52eea7a --- /dev/null +++ b/chap_2/un10.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +line_number = 0 +a_file = open('input.txt', 'r') +for line in a_file: + line_number += 1 + +print(line_number) From e40c25003a257216167153e2fcf4b0d78bdd1c10 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Tue, 22 Nov 2016 18:22:06 +0900 Subject: [PATCH 21/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC2=E7=AB=A011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_2/un11.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 chap_2/un11.py diff --git a/chap_2/un11.py b/chap_2/un11.py new file mode 100644 index 0000000..8dc9468 --- /dev/null +++ b/chap_2/un11.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +a_file = open('input.txt', 'r') +b_file = open('output.txt', 'w') + +for line in a_file: + line = line.replace("\t", " ") + print(line) From 532115856799f815a650a30ff26d8db16a855387 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Wed, 23 Nov 2016 20:41:42 +0900 Subject: [PATCH 22/23] =?UTF-8?q?100=E6=9C=AC=E3=83=8E=E3=83=83=E3=82=AF?= =?UTF-8?q?=E7=AC=AC2=E7=AB=A012?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_2/un12.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 chap_2/un12.py diff --git a/chap_2/un12.py b/chap_2/un12.py new file mode 100644 index 0000000..c939112 --- /dev/null +++ b/chap_2/un12.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +input_file = open('input.txt', 'r') +output1_file = open('col1.txt', 'w') +output2_file = open('col2.txt', 'w') + +lines = input_file.readlines() + +output1_file.write(lines[0]) +output1_file.close() +output2_file.write(lines[1]) +output2_file.close() From 342cae3e6c69153a4e9faf1de9ee99a314304272 Mon Sep 17 00:00:00 2001 From: Maruyama Date: Thu, 24 Nov 2016 21:27:02 +0900 Subject: [PATCH 23/23] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chap_2/un10.py | 8 ++++---- chap_2/un11.py | 11 +++++------ chap_2/un12.py | 16 ++++++---------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/chap_2/un10.py b/chap_2/un10.py index 52eea7a..cf8bf43 100644 --- a/chap_2/un10.py +++ b/chap_2/un10.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- line_number = 0 -a_file = open('input.txt', 'r') -for line in a_file: - line_number += 1 +with open('input.txt') as input_file: + for line in input_file: + line_number += 1 -print(line_number) + print("行数:"+str(line_number)) diff --git a/chap_2/un11.py b/chap_2/un11.py index 8dc9468..19ba885 100644 --- a/chap_2/un11.py +++ b/chap_2/un11.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- -a_file = open('input.txt', 'r') -b_file = open('output.txt', 'w') - -for line in a_file: - line = line.replace("\t", " ") - print(line) +with open('input.txt') as input_file: + with open('un11_output.txt','w') as output_file: + for line in input_file: + line = line.replace("\t", " ") + output_file.write(line) diff --git a/chap_2/un12.py b/chap_2/un12.py index c939112..0209f85 100644 --- a/chap_2/un12.py +++ b/chap_2/un12.py @@ -1,11 +1,7 @@ # -*- coding: utf-8 -*- -input_file = open('input.txt', 'r') -output1_file = open('col1.txt', 'w') -output2_file = open('col2.txt', 'w') - -lines = input_file.readlines() - -output1_file.write(lines[0]) -output1_file.close() -output2_file.write(lines[1]) -output2_file.close() +with open('input.txt') as input_file: + with open('col1.txt', 'w') as output1_file: + with open('col2.txt', 'w') as output2_file: + for line in iter(input_file.readlines()): + output1_file.writelines(line.split('\t')[0]+'\n') + output2_file.writelines(line.split('\t')[1]+'\n')