Skip to content

Instantly share code, notes, and snippets.

Avatar

Annika Noren AnnikaNoren

View GitHub Profile
View turkey_turtle.py
import turtle
t = turtle.Turtle()
s = turtle.getscreen()
def feather(r, angle, color):
for i in range(2):
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(r,angle)
turtle.left(180-angle)
View gist:35024aef4dcb2dbede01a333476126d5
from collections import Counter
def lcm_of_factors(list):
# empty dictionary
unique = {}
for i in range(0,len(list)):
number = list[i]
numbers = factors(number)
View primes.py
def factors(num):
i = 2
factors = []
while i <= num:
if (num % i) == 0:
factors.append(i)
num = num / i
else:
i = i + 1
return(factors)
View translate_v1.py
firstStr = 'aeiou'
secondStr = '01223'
translation = string.maketrans(firstStr, secondStr)
string = "apple"
new_string=string[::-1]
print('translated string: ', new_string.translate(translation)+'aca')
View final_translate.py
def encrypt_trans(word):
return(word[::-1].translate(word[::-1].maketrans("aeiou","01223"))+"aca")
View translation.py
# translation table - a dictionary
translation = {97: None, 98: None, 99: 105}
string = "abcdef"
print("Original string:", string)
# translate string
print("Translated string:", string.translate(translation))
View maketrans.py
firstString = "abc"
secondString = "ghi"
thirdString = "ab"
string = "abcdef"
translation = string.maketrans(firstString, secondString, thirdString)
print(translation)
print("Translated string:", string.translate(translation))
View encryption_v2.py
def encrypt(word):
replacers = {'a':0, 'e' :1, 'i':2, 'o':2,'u':3}
word_as_list = list(word[::-1])
replaced_list = [replacers.get(item,item) for item in word_as_list]
list_to_string = ''.join([str(elem) for elem in replaced_list])
list_to_string += 'aca'
View encryption_v1.py
def encrypt(word):
replacers = {'a':0, 'e' :1, 'i':2, 'o':2,'u':3}
word_as_list = list(word[::-1])
def replace(list, dictionary):
return [replacers.get(item, item) for item in list]
replaced_list = replace(word_as_list,replacers)
View disarm_v3.py
def disarm_short(num):
return (sum(int(j) ** (i+1) for i,j in enumerate(str(num))) == num)