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 QuestionA: | |
def __init__(self, question_dict): | |
self.question_dict = question_dict | |
class QuestionB: | |
def __init__(self, question_text, answer_dict): | |
self.question_text = question_text | |
self.answer_dict = answer_dict |
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
from lark import Transformer | |
cbat_grammar = """ | |
?literal : string | |
| char | |
| array | |
| map | |
| int | |
| float | |
| boolean |
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
from lark import Transformer, Lark | |
cbat_grammar = """ | |
?literal : string | |
| char | |
| array | |
| map | |
| int | |
| float | |
| boolean | |
array : "[" [literal ("," literal)*] "]" |
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
#See the terminal symbol 'arg_list' in cbat_grammar | |
#I noticed that functions on CodingBat were always in the form 'function_name' '(' 'arg' (',' 'whitespace_token'? arg)* ')' | |
#My grammar originally didn't have a way to deal with this. | |
#It could deal with multiple arguments in an array or map, but multiple- | |
#comma separated arguments not in a container literal would cause Lark to fail. | |
#To get around this, I figured I could treate the parentheses around the function arguments as a tuple, so... that's what I've done. | |
#Thus far it seems to work, though it feels inelegant. | |
from lark import Transformer, Lark |
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 Node: | |
def __init__(self, data, p_node=None, n_node=None): | |
self.p_node = p_node | |
self.n_node = n_node | |
self.data = data | |
class LList: | |
def __init__(self): | |
self.length = 0 | |
self.first = None |
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
import unittest | |
from itertools import cycle | |
""" | |
There's a very bad pattern in my code with having to run a filter operation in two separate methods on Game.players | |
How do I fix this? (See lines 16 and 30) | |
""" | |
class Game: | |
def __init__(self): | |
self.all_players = [] |
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 temp_converter(temps, mode, reversed): | |
return {'f': lambda x, y: [((temp - 32) * 5/9 + 273.15 if not y else (temp - 273.15) * 9/5 + 32) for temp in x], | |
'k': lambda x, y: x, | |
'c': lambda x, y: [temp + (273.15 if not y else -273.15) for temp in x]}[mode](temps, reversed) | |
def format_outputs(temps, mode): | |
return f'°{mode[-1].upper()}, '.join(map(lambda temp: str(round(temp, 2)), temps)) + f'°{mode[-1].upper()}' | |
if __name__ == '__main__': | |
mode = input('What temperature scales would you like to convert between? ').lower() |
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
from itertools import permutations | |
class LaceWords: | |
def __init__(self, dictionary=None, interface=None): | |
self.dictionary = dictionary | |
if not dictionary: | |
self.dictionary = 'scrabble_2020_dict' | |
self.interface = interface | |
if not self.interface: |