Skip to content

Instantly share code, notes, and snippets.

@owgreen
owgreen / verb_post_one_liner.py
Created July 8, 2017 02:58
第一回試験のワンラインバージョン
vowel = ('a','i','u','e','o')
d = {'write':'wrote', 'go':'went', 'read':'read'}
verb_post = lambda x: d[x] if x in d else (x + 'd' if x[-1] =='e' else(x[:-1] + 'ied' if x[-1] == 'y' and x[-2] not in vowel else(x + 'ked' if x[-1] == 'c' else (x + 'ed'))))
@owgreen
owgreen / sum7_one_liner.py
Created July 8, 2017 02:34
試験の問題のワンラインバージョン
sum7 = lambda lst:sum([e if e!= 7 or i+1 >= len(lst) else lst[i+1] + e for i, e in enumerate(lst)])
linear_merge = lambda x, y: sorted(x+y)
def remove_adjacent(x):
cp = x[:]
for i, v in enumerate(cp):
if v == cp[i-1]:
x.remove(v)
return x
sort_last = lambda x: sorted(x,key=lambda y: y[-1])
@owgreen
owgreen / front_x.py
Created June 23, 2017 11:11
第3回
def front_x(x):
l1, l2 = [], []
for e in x:
if e.startswith('x'):
l1.append(e)
else:
l2.append(e)
return sorted(l1) + sorted(l2)
@owgreen
owgreen / match_ends.py
Last active June 23, 2017 10:51
第三回
match_ends = lambda x: len([e for e in x if len(e) >= 2 and e[0] == e[-1]])
def not_bad(s):
lst = s.split(' ')
try:
n,b = lst.index('not'), lst.index('bad')
except:
return s
if n < b:
lst[n+1:b+1] = ''
lst[n] = 'good'
return ' '.join(lst)
@owgreen
owgreen / fix_first.py
Created June 22, 2017 11:09
第3回
fix_first = lambda x: x[0] + x[1:].replace(x[0], '*')