This file contains 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
# 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), |
This file contains 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
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: |
This file contains 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
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: |
This file contains 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
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", ""])) |
This file contains 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
# 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")) |
This file contains 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
# 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 |
This file contains 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
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) + "." |
This file contains 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
def unique_str(str): | |
unique = "" | |
for char in str: | |
if char not in unique: | |
unique += char | |
else: | |
continue | |
if unique == str: | |
print(True) |
This file contains 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
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]: |
This file contains 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
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': |