This file contains hidden or 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 lyric_frequencies(lyrics_db): | |
| ''' | |
| create a dictionary with | |
| keys = unique lyrics (words) | |
| vals = number of occurrences in the lyrics db | |
| ''' | |
| lyrics_dict = {} | |
| # loop through lyrics_db elements | |
| for lyric in lyrics_db: | |
| if lyric in lyrics_dict: |
This file contains hidden or 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 towers_rec(n, home, destination, temp): | |
| if n == 1: | |
| moves.append((home+' to '+destination)) | |
| else: | |
| towers_rec(n-1, home, temp, destination) | |
| towers_rec(1, home, destination, temp) | |
| towers_rec(n-1, temp, destination, home) | |
| if __name__ == "__main__": | |
| print('Elements are stacked at position A, which is \'home\'.\n \ |
This file contains hidden or 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 fib_eff(n, dict): | |
| ''' | |
| performace-aware recursive algorithm: | |
| keep track of computed Fibonacci terms in a dictionary; | |
| limit computation to terms not in the dictionary | |
| ''' | |
| if n in dict: | |
| return dict[n] | |
| else: | |
| fibn = fib_eff(n-1, dict) + fib_eff(n-2, dict) |
This file contains hidden or 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
| import random | |
| def bubble_sorted_list(ulist): | |
| ''' | |
| sort ulist by pairwise checks (aka BUBBLE SORT): | |
| pairwise comparisons from start (index 0) to end (index n), | |
| shifting higher values toward the end | |
| ''' | |
| swap = True | |
| while swap: |
This file contains hidden or 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
| import random | |
| def selection_sorted_list(ulist): | |
| ''' | |
| sort a list recursively by shifting the minimum value of the portion of the | |
| list to the right of a comparator index to the comparator index; the index | |
| increases by 1 on each pass up to len(list) | |
| ''' | |
| uoindex = 0 | |
| while uoindex != len(ulist): |
This file contains hidden or 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
| I deployed to Heroku and custom fonts didn't work. Details of my starting point below. | |
| Fixed in 2 steps: | |
| 1. In application.rb file, in class Application < Rails::Application, added: | |
| config.assets.paths << Rails.root.join("app","assets","fonts") | |
| 2. In application.scss file, in @font-face, changed src: url('...') to font-url('...'); e.g.: | |
| src: font-url('Aileron/Aileron-Regular.otf') format('opentype'); | |
| Redeployed to Heroku and custom fonts worked. | |
| --- | |
| Starting point details (this all worked for a local deploy, but not when deployed on Heroku): |
This file contains hidden or 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 setpy(): | |
| """ | |
| python sets are collections of objects which are: | |
| unique | |
| unordered | |
| unchangeable* | |
| * where unchangeable means individual items can't be replaced in place, but items can be removed and new items added | |
| """ | |
| # unique and unsorted |
This file contains hidden or 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
| # select letters one at a time to guess mystery word | |
| import string | |
| import random | |
| from words_json import words | |
| def get_valid_word(words): | |
| word = random.choice(words) | |
| while '-' in word or ' ' in word: | |
| word = random.choice(words) |
This file contains hidden or 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
| import random | |
| def is_win(g, s): | |
| '''check for a win, assign win value, return boolean''' | |
| if all(g[i] == s[i] for i in range(len(s))): | |
| win = True | |
| print(f'You won! The code was {s}') | |
| return win | |
| else: | |
| win = False |
This file contains hidden or 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
| # select letters one at a time to guess mystery word | |
| import string | |
| import random | |
| from words_json import words | |
| def get_valid_word(words): | |
| word = random.choice(words) | |
| while '-' in word or ' ' in word: | |
| word = random.choice(words) |
NewerOlder