Skip to content

Instantly share code, notes, and snippets.

View sashiyama's full-sized avatar
🌐

Yoshi sashiyama

🌐
View GitHub Profile
@sashiyama
sashiyama / verb_post.py
Created July 7, 2018 01:04
verb_post.py
def verb_post(v):
irregular_verb = {"write": "wrote", "go": "went", "read": "read"}
for key, value in irregular_verb.items():
if key == v:
return value
if v[-1] == "c":
return v + "ked"
elif v[-1] == "e":
return v + "d"
elif v[-1] == "y":
@sashiyama
sashiyama / sum7.py
Created July 7, 2018 00:47
sum7.py
def sum7(list):
if len(list) < 1:
return -1
else:
count = 0
for x in list:
if x == 7:
try:
list[count + 1] *= 2
count += 1
@sashiyama
sashiyama / wc.py
Created June 30, 2018 00:56
wc.py
import sys
import re
def count_word(lines):
words = {}
sum = 0
for line in lines:
line = re.sub(r'\r\n|\n|\.|,|-|\"|\'|\[|\]|_|\*|:|\;|\(|\)|\/|\&|!|\?', ' ', line).lower()
n = line.split()
sum += len(n)
@sashiyama
sashiyama / nl.py
Last active June 30, 2018 00:33
nl.py
import sys
def nl(lines):
i = 1
for line in lines:
if line == '\n':
print("{0}".format(line), end="")
else:
print(" {0} {1}".format(i, line), end="")
i += 1
@sashiyama
sashiyama / fizz_buzz_one_liner.py
Last active June 26, 2018 08:23
FizzBuss one liner
import re
def fb(x):
return re.sub(r'[0-9]+', '', str((['Fizz'] + list(range((x % 3))))[x % 3]) + str((['Buzz'] + list(range((x % 5))))[x % 5]))
i = 1
while i <= 200:
print(i, fb(i))
i = i + 1
def fb(n):
if n % 15 == 0:
return "FizzBuzz"
elif n % 3 == 0:
return "Fizz"
elif n % 5 == 0:
return "Buzz"
else:
return ""