Skip to content

Instantly share code, notes, and snippets.

@nozma
nozma / Main.py
Last active August 17, 2017 13:13
# coding: utf-8
def cipher(S):
return ''.join(chr(219 - ord(c)) if c.islower() else c for c in S)
S = "abcDe"
print(cipher(S))
print(cipher(cipher(S)))
@nozma
nozma / Main.py
Last active August 17, 2017 13:06
# coding: utf-8
def n_gram(n, s):
return [s[i:i+n] for i in range(0, len(s)-n+1)]
print(n_gram(2, 'I am an NLPer'))
@nozma
nozma / Main.py
Last active August 17, 2017 13:04
# coding: utf-8
s = 'Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can.'
target = 1, 5, 6, 7, 8, 9, 15, 16, 19
result = [w[: 1 if i in target else 2] for i, w in enumerate(s.split(), 1)]
print(result)
@nozma
nozma / Main.py
Last active August 17, 2017 12:16
# coding: utf-8
s = 'Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.'
# 単語毎のリストに分解してから,.を除外し文字数をカウント
result = [len(w.rstrip(',.')) for w in s.split()]
print(result)
# coding: utf-8
s1 = 'パトカー'
s2 = 'タクシー'
s = ''.join(i+j for i, j in zip(s1, s2))
print(s)
@nozma
nozma / Main.py
Last active August 16, 2017 15:08
# coding: utf-8
import numpy.random as rd
def gen_typo(S):
if len(S) <= 4:
return S
else:
idx = [0]
idx.extend(rd.choice(range(1, len(S)-1), len(S)-2, replace=False))
@nozma
nozma / Main.py
Last active August 16, 2017 14:06
# coding: utf-8
def cipher(S):
result = []
for i in range(len(S)):
if(S[i].islower()):
result.append(chr(219 - ord(S[i])))
else:
result.append(S[i])
return ''.join(result)
@nozma
nozma / Main.py
Last active August 16, 2017 14:38
# coding: utf-8
def gen_sentence(x, y, z):
return "{}時の{}は{}".format(x, y, z)
x = 12
y = '気温'
z = 22.4
print(gen_sentence(x, y, z))
@nozma
nozma / Main.py
Last active August 16, 2017 14:36
# coding: utf-8
# 2つのバイグラムの和集合、積集合、差集合
def bi_gram(s):
result = []
for i in range(0, len(s)-1):
result.append(s[i:i+2])
return result
s1 = 'paraparaparadise'
@nozma
nozma / Main.py
Last active August 16, 2017 14:34
# coding: utf-8
def n_gram(n, s):
result = []
for i in range(0, len(s)-n+1):
result.append(s[i:i+n])
return result
print(n_gram(2, 'I am an NLPer'))