Skip to content

Instantly share code, notes, and snippets.

View joan0fsnark's full-sized avatar
:octocat:

Alena joan0fsnark

:octocat:
View GitHub Profile
@joan0fsnark
joan0fsnark / bracket_trackit.py
Created March 23, 2022 19:16
Keep Track of Brackets (interview q)
# Will use this to keep track of type opened
# (1/2/3 == curved/curly/square)
opentype = []
typedict = {
'(': (True, 1),
')': (False, 1),
'[': (True, 2),
']': (False, 2),
'{': (True, 3),
@joan0fsnark
joan0fsnark / count_first_letter.py
Created September 6, 2021 21:06
Function takes a dictionary called 'names' as a parameter; 'names' should be a dictionary where the key is a last name and the value is a list of first names. Returns a new dictionary where each key is the first letter of a last name, and the value is the number of people whose last name begins with that letter.
def count_first_letter(names):
letters = {}
for key in names:
first_letter = key[0]
if first_letter not in letters:
letters[first_letter] = 0
letters[first_letter] += len(names[key])
return letters
# Uncomment these function calls to test your function:
@joan0fsnark
joan0fsnark / frequency.py
Created September 6, 2021 20:55
Function that takes a list of elements named 'words' as a parameter and returns a dictionary containing the frequency of each element in 'words'.
def frequency_dictionary(words):
dict = {}
for word in words:
if word not in dict:
dict[word] = 0
dict[word] += 1
return dict
# Uncomment these function calls to test your function:
@joan0fsnark
joan0fsnark / word_lengths.py
Created September 6, 2021 20:51
The function takes in a list of strings named 'words' as a parameter and return a dictionary of key/value pairs where every key is a word in words and every value is the length of that word.
def word_length_dictionary(words):
dict = {}
for word in words:
dict[word] = len(word)
return dict
# Uncomment these function calls to test your function:
print(word_length_dictionary(["apple", "dog", "cat"]))
# should print {"apple":5, "dog": 3, "cat":3}
print(word_length_dictionary(["a", ""]))
@joan0fsnark
joan0fsnark / make_spoonerism.py
Created September 6, 2021 20:00
Takes in two words and returns the two with first letters swapped
# Write your make_spoonerism function here:
def make_spoonerism(word1, word2):
return word2[0] + word1[1:]+" "+word1[0] + word2[1:]
# Uncomment these function calls to test your function:
print(make_spoonerism("Codecademy", "Learn"))
# should print Lodecademy Cearn
print(make_spoonerism("Hello", "world!"))
# should print wello Horld!
print(make_spoonerism("a", "b"))
@joan0fsnark
joan0fsnark / reverse_string.py
Created September 6, 2021 19:55
Reverses given string
# Write your reverse_string function here:
def reverse_string(word):
reverse_word = ""
for i in range(len(word)-1, -1, -1):
reverse_word += word[i]
return reverse_word
# Uncomment these function calls to test your function:
print(reverse_string("Codecademy"))
# should print ymedacedoC
@joan0fsnark
joan0fsnark / restaurant_app.py
Last active November 15, 2021 00:31 — forked from codecademydev/script.py
Codecademy: You’ve started position as the lead programmer for the family-style Italian restaurant Basta Fazoolin’ with My Heart. The restaurant has been doing fantastically and seen a lot of growth lately. You’ve been hired to keep things organized. [Creates menus, calculates bills, and has Franchise and Business classes to manage expansion]
class Menu:
def __init__(self, name, items, start_time, end_time):
self.name = name
self.items = items
self.start_time = start_time
self.end_time = end_time
def __repr__(self):
return self.name + ' menu is available from ' + str(self.start_time) + ' - ' + str(self.end_time) + "."
@joan0fsnark
joan0fsnark / IsUnique.py
Created June 26, 2021 23:13
Determines if a string has all unique characters.
def unique_str(str):
unique = ""
for char in str:
if char not in unique:
unique += char
else:
continue
if unique == str:
print(True)
@joan0fsnark
joan0fsnark / palindrome.py
Created June 9, 2021 02:57
Find palindromes in list of words
list = ['radar', 'racecar', 'grumble']
for word in list:
palindrome = True
start = 0
end = len(word) - 1 # pos of last letter
while start < end:
if word[start] != word[end]:
@joan0fsnark
joan0fsnark / 10minwalk.py
Last active May 27, 2021 18:41
CodeWars: Take a Ten-Minute Walk (Python)
def is_valid_walk(walk):
ns = 0
ew = 0
if len(walk) == 10:
for step in walk:
if step == 'n':
ns += 1
if step == 's':
ns -= 1
if step == 'w':