Last active
April 29, 2017 20:44
-
-
Save uenoku/6edb07a1ecbe1017a073e7c753150086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://www.cl.ecei.tohoku.ac.jp/nlp100/ | |
from collections import defaultdict | |
import string | |
def p0(s): | |
return s[::-1] | |
def p1(s): | |
return s[0::2] | |
def p2(l, r): | |
s = "" | |
for i in range(len(l) + len(r)): | |
s += l[i // 2] if i % 2 == 0 else r[i // 2] | |
return s | |
def p3(s): | |
return [len(ele) for ele in s.split(" ")] | |
def p4(s): | |
num = [1, 5, 6, 7, 8, 9, 15, 16, 19] | |
s = s.split(" ") | |
s = [s[i][0] if (i - 1) in num else s[i][:2] for i in range(len(s))] | |
dic = {s[i]: i + 1 for i in range(len(s))} | |
return dic | |
def p5(s, n, word=True): | |
if word: s = s.split(" ") | |
if (len(s) < n): return {} | |
d = defaultdict(int) | |
for i in range(len(s)): | |
if i + n >= len(s): break | |
if " " in s[i:i + n]: continue | |
d[s[i:i + n]] += 1 | |
return d | |
def p6(l, r): | |
L = set([(key) for key in p5(l, 2, False)]) | |
R = set([(key) for key in p5(r, 2, False)]) | |
return (L | R, L & R, L ^ R) | |
def p7(x, y, z): | |
return "{0}時の{1}は{2}".format(x, y, z) | |
def p8(s): | |
after = "" | |
for i in s: | |
if i in string.ascii_lowercase: | |
after += chr(219 - ord(i)) | |
else: | |
after += i | |
return after | |
if __name__ == "__main__": | |
print(p8("hogehoge")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment