Skip to content

Commit

Permalink
Merge pull request #6 from tmu-nlp/shota
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyama-hajime authored Apr 16, 2024
2 parents dd3ef30 + 4eef4b8 commit ea394a7
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions shota/chapter01/knock00.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
text = "stressed"
print(text[::-1])
5 changes: 5 additions & 0 deletions shota/chapter01/knock01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
text = "パタトクカシーー"
for i in range(len(text)):
if i%2 != 0:
print(text[i],end = "")
print("")
4 changes: 4 additions & 0 deletions shota/chapter01/knock02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
text1 = "パトカー"
text2 = "タクシー"
for i in range(4):
print(text1[i]+text2[i],end = "")
2 changes: 2 additions & 0 deletions shota/chapter01/knock03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
text = "Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics."
print(text.split())
12 changes: 12 additions & 0 deletions shota/chapter01/knock04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
text = "Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can."
ls = text.split()
num = [1,5,6,7,8,9,15,16,19]
ans = {}

for i in range(len(ls)):
if i+1 in num:
ans[ls[i][0]] = i+1
else:
ans[ls[i][0:2]] = i+1

print(ans)
13 changes: 13 additions & 0 deletions shota/chapter01/knock05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def n_gram(text,n):
ls = []
for i in range(0,len(text)-n+1):
ls.append(text[i:i+n])
return ls

text = "I am an NLPer"
text_ = text.split()

print(text_)

print(n_gram(text,2))
print(n_gram(text_,2))
25 changes: 25 additions & 0 deletions shota/chapter01/knock06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
text1 = "paraparaparadise"
text2 = "paragraph"

def n_gram(text,n):
ls = []
for i in range(0,len(text)-n+1):
ls.append(text[i:i+n])
return ls

X = set(n_gram(text1,2))
Y = set(n_gram(text2,2))

print("union >>",X | Y)
print("intersection >>",X & Y)
print("difference >>",X - Y)

if "se" in X:
print("'se' is in X")
else:
print("'se' is not in X")

if "se" in Y:
print("'se' is in Y")
else:
print("'se' is not in Y")
4 changes: 4 additions & 0 deletions shota/chapter01/knock07.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
print("input X,Y,Z >> ",end = "")
X,Y,Z = map(str,input().split())

print("{}時の{}は{}".format(X,Y,Z))
25 changes: 25 additions & 0 deletions shota/chapter01/knock08.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
text = input()

def ciper(text):
cipered = ""
for c in text:
asc = ord(c)
if 97 <= asc <= 122:
c = chr(219-asc)
cipered += c
return cipered

def deciper(text):
decipered = ""
for c in text:
asc = ord(c)
if 97 <= asc <= 122:
c = chr(219-asc)
decipered += c
return decipered

cipered_text = ciper(text)
print(" cipered_text >> ",cipered_text)

decipered_text = deciper(cipered_text)
print("decipered_text >> ",decipered_text)
16 changes: 16 additions & 0 deletions shota/chapter01/knock09.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import random
text = list(input().split())

for words in text:
if len(words) > 4:
head = words[0]
tail = words[len(words)-1]

body = list(words[1:len(words)-1])
random.shuffle(body)
body = "".join(body)

words = head + str(body) + tail

print(words,end=" ")
print("")

0 comments on commit ea394a7

Please sign in to comment.