Best Python code snippet using lemoncheesecake
app.py
Source:app.py
1import dash2import dash_html_components as html3import dash_bootstrap_components as dbc4import dash_core_components as dcc5from dash.dependencies import Input, Output, State6import numpy as np7import time8from datetime import datetime9import fetch10from components import styles11from components import charts as chrt12from components import headlines13from components import headline_field as hf14external_stylesheets = [dbc.themes.BOOTSTRAP]15app = dash.Dash(__name__, external_stylesheets=external_stylesheets, update_title=None)16server = app.server17app.title = 'MSSMW'18# fetch data19MSSMW_DATE, LW_ENDDATE, SP500, DJIA, NASDAQ, EURUSD, OIL, GOLD = fetch.get_MSSMW()20MSSMW_DATE = str(MSSMW_DATE.iloc[0])[:10]21LW_ENDDATE = str(LW_ENDDATE)[:10]22fig_SP500 = chrt.comparative_main(SP500, "Standard and Poor's 500", draw_label = True)23fig_DJIA = chrt.comparative_main(DJIA, "Dow Jones Industrial Average")24fig_NASDAQ = chrt.comparative_main(NASDAQ, "NASDAQ Composite Index")25fig_EURUSD = chrt.comparative_main(EURUSD, "EUR/USD")26fig_OIL = chrt.comparative_main(OIL, "Crude Oil Spot Price")27fig_GOLD = chrt.comparative_main(GOLD, "Gold Spot Price")28#fetch headlines and create used/unused databases29hist_headline_base = headlines.get_headlines(MSSMW_DATE)30modern_headline_base = headlines.get_modern_headlines()31# Define the app32app.layout = html.Div(style = {'backgroundColor': styles.colors['background'], 'marginTop': -50, 'marginLeft':-20},33children=[34 dbc.Row([dbc.Col(), html.Img(src=app.get_asset_url('logo1.png'), style = {'height':150, 'justify':'center', 'marginTop':50}), dbc.Col()], style = styles.navbar),35 dbc.Row([dbc.Col([html.P('Historical Headlines', style = styles.similarity_text)], style = styles.content_field_left),36 dbc.Col([html.P('The week ended ' + LW_ENDDATE + ' is the most similar to the week ended '+ MSSMW_DATE + '.', style = styles.similarity_text)], style = styles.content_field_center, xs = 6, sm = 6, md = 6, lg = 6, xl = 6),37 dbc.Col([html.P('Modern Headlines', style = styles.similarity_text)],style = styles.content_field_right)]),38 dbc.Row([ # this will be the main row with headline columns and graph column39 dbc.Col([hf.headline_field(hist_headline_base, 'headline_1', 'fader_1'), 40 hf.headline_field(hist_headline_base, 'headline_2', 'fader_2'),41 hf.headline_field(hist_headline_base, 'headline_3', 'fader_3'), 42 hf.headline_field(hist_headline_base, 'headline_4', 'fader_4'), 43 hf.headline_field(hist_headline_base, 'headline_5', 'fader_5'), 44 hf.headline_field(hist_headline_base, 'headline_6', 'fader_6'),45 hf.headline_field(hist_headline_base, 'headline_7', 'fader_7'),46 hf.headline_field(hist_headline_base, 'headline_8', 'fader_8'), 47 hf.headline_field(hist_headline_base, 'headline_9', 'fader_9'),48 hf.headline_field(hist_headline_base, 'headline_10', 'fader_10'), 49 hf.headline_field(hist_headline_base, 'headline_11', 'fader_11'), 50 hf.headline_field(hist_headline_base, 'headline_12', 'fader_12'), 51 dcc.Interval(id = 'interval-component-1',52 interval=4*1000,53 n_intervals=0),54 dcc.Interval(id = 'interval-component-2',55 interval=2*1000,56 n_intervals=0)], style = styles.content_field_left),57 58 dbc.Col([dcc.Graph(59 id = 'SP500',60 figure = fig_SP500,61 config= {62 'displayModeBar': False,63 'displaylogo': False, 64 }65 ),66 dcc.Graph(67 id = 'DJIA',68 figure = fig_DJIA,69 config= {70 'displayModeBar': False,71 'displaylogo': False, 72 }73 ),74 dcc.Graph(75 id = 'NASDAQ',76 figure = fig_NASDAQ,77 config= {78 'displayModeBar': False,79 'displaylogo': False, 80 }81 ),82 dcc.Graph(83 id = 'EURUSD',84 figure = fig_EURUSD,85 config= {86 'displayModeBar': False,87 'displaylogo': False, 88 }89 ),90 dcc.Graph(91 id = 'OIL',92 figure = fig_OIL,93 config= {94 'displayModeBar': False,95 'displaylogo': False, 96 }97 ),98 dcc.Graph(99 id = 'GOLD',100 figure = fig_GOLD,101 config= {102 'displayModeBar': False,103 'displaylogo': False, 104 }105 )], style= styles.content_field_center, xs=6, sm=6, md=6, lg = 6, xl = 6), #graphs106 107 dbc.Col([hf.modern_headline_field(modern_headline_base,'modern-headline-1', 'modern-fader-1'),108 hf.modern_headline_field(modern_headline_base,'modern-headline-2', 'modern-fader-2'),109 hf.modern_headline_field(modern_headline_base,'modern-headline-3', 'modern-fader-3'),110 hf.modern_headline_field(modern_headline_base,'modern-headline-4', 'modern-fader-4'),111 hf.modern_headline_field(modern_headline_base,'modern-headline-5', 'modern-fader-5'),112 hf.modern_headline_field(modern_headline_base,'modern-headline-6', 'modern-fader-6'),113 hf.modern_headline_field(modern_headline_base,'modern-headline-7', 'modern-fader-7'),114 hf.modern_headline_field(modern_headline_base,'modern-headline-8', 'modern-fader-8'),115 hf.modern_headline_field(modern_headline_base,'modern-headline-9', 'modern-fader-9'),116 hf.modern_headline_field(modern_headline_base,'modern-headline-10', 'modern-fader-10'),117 hf.modern_headline_field(modern_headline_base,'modern-headline-11', 'modern-fader-11')], style = styles.content_field_right)118 ]),119 ]120 )121@app.callback(122 Output('modern-fader-1', 'children'),123 Output('modern-fader-1', 'is_in'),124 Output('modern-fader-2', 'children'),125 Output('modern-fader-2', 'is_in'),126 Output('modern-fader-3', 'children'),127 Output('modern-fader-3', 'is_in'),128 Output('modern-fader-4', 'children'),129 Output('modern-fader-4', 'is_in'),130 Output('modern-fader-5', 'children'),131 Output('modern-fader-5', 'is_in'),132 Output('modern-fader-6', 'children'),133 Output('modern-fader-6', 'is_in'),134 Output('modern-fader-7', 'children'),135 Output('modern-fader-7', 'is_in'),136 Output('modern-fader-8', 'children'),137 Output('modern-fader-8', 'is_in'),138 Output('modern-fader-9', 'children'),139 Output('modern-fader-9', 'is_in'),140 Output('modern-fader-10', 'children'),141 Output('modern-fader-10', 'is_in'),142 Output('modern-fader-11', 'children'),143 Output('modern-fader-11', 'is_in'),144 Input('interval-component-1', 'n_intervals'),145 Input('interval-component-2', 'n_intervals'),146 State('modern-fader-1', 'children'),147 State('modern-fader-1', 'is_in'),148 State('modern-fader-2', 'children'),149 State('modern-fader-2', 'is_in'),150 State('modern-fader-3', 'children'),151 State('modern-fader-3', 'is_in'),152 State('modern-fader-4', 'children'),153 State('modern-fader-4', 'is_in'),154 State('modern-fader-5', 'children'),155 State('modern-fader-5', 'is_in'),156 State('modern-fader-6', 'children'),157 State('modern-fader-6', 'is_in'),158 State('modern-fader-7', 'children'),159 State('modern-fader-7', 'is_in'),160 State('modern-fader-8', 'children'),161 State('modern-fader-8', 'is_in'),162 State('modern-fader-9', 'children'),163 State('modern-fader-9', 'is_in'),164 State('modern-fader-10', 'children'),165 State('modern-fader-10', 'is_in'),166 State('modern-fader-11', 'children'),167 State('modern-fader-11', 'is_in'),168)169def updater(n_intervals, n_intervals_2, children_1, is_in_1, children_2, is_in_2, children_3, is_in_3, children_4, is_in_4, children_5, is_in_5, children_6, is_in_6, children_7, is_in_7, children_8, is_in_8, children_9, is_in_9, children_10, is_in_10, children_11, is_in_11):170 ctx = dash.callback_context.triggered171 if ctx[0]['prop_id'] == 'interval-component-1.n_intervals':172 parameter_list = [children_1, is_in_1, children_2, is_in_2, children_3, is_in_3, children_4, is_in_4, children_5, is_in_5, children_6, is_in_6, children_7, is_in_7, children_8, is_in_8, children_9, is_in_9, children_10, is_in_10, children_11, is_in_11]173 chosen_index = int(np.random.randint(0, 11))*2+1174 parameter_list[chosen_index] = False175 return parameter_list[0], parameter_list[1], parameter_list[2], parameter_list[3], parameter_list[4], parameter_list[5], parameter_list[6], parameter_list[7], parameter_list[8], parameter_list[9], parameter_list[10], parameter_list[11], parameter_list[12], parameter_list[13], parameter_list[14], parameter_list[15], parameter_list[16], parameter_list[17], parameter_list[18], parameter_list[19], parameter_list[20], parameter_list[21]176 else:177 parameter_list = [children_1, is_in_1, children_2, is_in_2, children_3, is_in_3, children_4, is_in_4, children_5, is_in_5, children_6, is_in_6, children_7, is_in_7, children_8, is_in_8, children_9, is_in_9, children_10, is_in_10, children_11, is_in_11]178 try:179 chosen_index = parameter_list.index(False)180 parameter_list[chosen_index] = True181 name_id = int(chosen_index+1)/2182 parameter_list[chosen_index-1] = hf.modern_headline_field(modern_headline_base,'modern-headline-'+str(name_id), 'modern-fader-'+str(name_id))183 return parameter_list[0], parameter_list[1], parameter_list[2], parameter_list[3], parameter_list[4], parameter_list[5], parameter_list[6], parameter_list[7], parameter_list[8], parameter_list[9], parameter_list[10], parameter_list[11], parameter_list[12], parameter_list[13], parameter_list[14], parameter_list[15], parameter_list[16], parameter_list[17], parameter_list[18], parameter_list[19], parameter_list[20], parameter_list[21]184 except ValueError:185 return children_1, is_in_1, children_2, is_in_2, children_3, is_in_3, children_4, is_in_4, children_5, is_in_5, children_6, is_in_6, children_7, is_in_7, children_8, is_in_8, children_9, is_in_9, children_10, is_in_10, children_11, is_in_11186@app.callback(187 Output('fader_1', 'children'),188 Output('fader_1', 'is_in'),189 Output('fader_2', 'children'),190 Output('fader_2', 'is_in'),191 Output('fader_3', 'children'),192 Output('fader_3', 'is_in'),193 Output('fader_4', 'children'),194 Output('fader_4', 'is_in'),195 Output('fader_5', 'children'),196 Output('fader_5', 'is_in'),197 Output('fader_6', 'children'),198 Output('fader_6', 'is_in'),199 Output('fader_7', 'children'),200 Output('fader_7', 'is_in'),201 Output('fader_8', 'children'),202 Output('fader_8', 'is_in'),203 Output('fader_9', 'children'),204 Output('fader_9', 'is_in'),205 Output('fader_10', 'children'),206 Output('fader_10', 'is_in'),207 Output('fader_11', 'children'),208 Output('fader_11', 'is_in'),209 Input('interval-component-1', 'n_intervals'),210 Input('interval-component-2', 'n_intervals'),211 State('fader_1', 'children'),212 State('fader_1', 'is_in'),213 State('fader_2', 'children'),214 State('fader_2', 'is_in'),215 State('fader_3', 'children'),216 State('fader_3', 'is_in'),217 State('fader_4', 'children'),218 State('fader_4', 'is_in'),219 State('fader_5', 'children'),220 State('fader_5', 'is_in'),221 State('fader_6', 'children'),222 State('fader_6', 'is_in'),223 State('fader_7', 'children'),224 State('fader_7', 'is_in'),225 State('fader_8', 'children'),226 State('fader_8', 'is_in'),227 State('fader_9', 'children'),228 State('fader_9', 'is_in'),229 State('fader_10', 'children'),230 State('fader_10', 'is_in'),231 State('fader_11', 'children'),232 State('fader_11', 'is_in'),233)234def updater2(n_intervals, n_intervals_2, children_1, is_in_1, children_2, is_in_2, children_3, is_in_3, children_4, is_in_4, children_5, is_in_5, children_6, is_in_6, children_7, is_in_7, children_8, is_in_8, children_9, is_in_9, children_10, is_in_10, children_11, is_in_11):235 ctx = dash.callback_context.triggered236 if ctx[0]['prop_id'] == 'interval-component-1.n_intervals':237 parameter_list = [children_1, is_in_1, children_2, is_in_2, children_3, is_in_3, children_4, is_in_4, children_5, is_in_5, children_6, is_in_6, children_7, is_in_7, children_8, is_in_8, children_9, is_in_9, children_10, is_in_10, children_11, is_in_11]238 chosen_index = int(np.random.randint(0, 11))*2+1239 parameter_list[chosen_index] = False240 return parameter_list[0], parameter_list[1], parameter_list[2], parameter_list[3], parameter_list[4], parameter_list[5], parameter_list[6], parameter_list[7], parameter_list[8], parameter_list[9], parameter_list[10], parameter_list[11], parameter_list[12], parameter_list[13], parameter_list[14], parameter_list[15], parameter_list[16], parameter_list[17], parameter_list[18], parameter_list[19], parameter_list[20], parameter_list[21]241 else:242 parameter_list = [children_1, is_in_1, children_2, is_in_2, children_3, is_in_3, children_4, is_in_4, children_5, is_in_5, children_6, is_in_6, children_7, is_in_7, children_8, is_in_8, children_9, is_in_9, children_10, is_in_10, children_11, is_in_11]243 try:244 chosen_index = parameter_list.index(False)245 parameter_list[chosen_index] = True246 name_id = int(chosen_index+1)/2247 parameter_list[chosen_index-1] = hf.headline_field(hist_headline_base,'headline_'+str(name_id), 'fader_'+str(name_id))248 return parameter_list[0], parameter_list[1], parameter_list[2], parameter_list[3], parameter_list[4], parameter_list[5], parameter_list[6], parameter_list[7], parameter_list[8], parameter_list[9], parameter_list[10], parameter_list[11], parameter_list[12], parameter_list[13], parameter_list[14], parameter_list[15], parameter_list[16], parameter_list[17], parameter_list[18], parameter_list[19], parameter_list[20], parameter_list[21]249 except ValueError:250 return children_1, is_in_1, children_2, is_in_2, children_3, is_in_3, children_4, is_in_4, children_5, is_in_5, children_6, is_in_6, children_7, is_in_7, children_8, is_in_8, children_9, is_in_9, children_10, is_in_10, children_11, is_in_11251# Run the app252if __name__ == '__main__':...
test_tree.py
Source:test_tree.py
...9 root, E = t.evidence(b"World")10 assert len(E) == 211 store = dict((e.identity(), e) for e in E)12 t2 = Tree(store, root)13 assert t2.is_in(b"World")14def test_store(rstore):15 l = Leaf(b"Hello", b"Hello")16 rstore[l.identity()] = l17 assert rstore[l.identity()].identity() == l.identity()18def test_store_tree(rstore):19 t = Tree(store=rstore)20 from os import urandom21 for _ in range(100):22 item = urandom(32)23 t.add(item, item)24 assert t.is_in(item)25 assert not t.is_in(urandom(32))26def test_leaf_isin():27 l = Leaf(b"Hello", b"Hello")28 store = {l.identity() : l}29 b = l.add(store, b"Woitemrld", b"Woitemrld")30 assert l.is_in(store, b"Hello", b"Hello")31def test_leaf_isin_map():32 l = Leaf(item=b"Hello", key=b"World")33 store = {l.identity() : l}34 b = l.add(store, b"World", b"World")35 assert l.is_in(store, item=b"Hello", key=b"World")36def test_Branch_isin():37 l = Leaf(b"Hello", b"Hello")38 store = {l.identity() : l}39 b = l.add(store, b"World", b"World")40 assert b.is_in(store, b"Hello", b"Hello")41 assert b.is_in(store, b"World", b"World")42def test_Branch_isin_map():43 l = Leaf(item=b"Hello", key=b"A")44 store = {l.identity() : l}45 b = l.add(store, item=b"World", key=b"B")46 assert b.is_in(store, b"Hello", b"A")47 assert b.is_in(store, b"World", b"B")48 assert not b.is_in(store, b"World", b"C")49def test_Branch_multi():50 l = Leaf(b"Hello", b"Hello")51 store = {l.identity() : l}52 b = l.multi_add(store, [b"B", b"C"], [b"B", b"C"])53 b.check(store)54 assert b.is_in(store, b"B", b"B")55 assert b.is_in(store, b"C", b"C")56 assert b.is_in(store, b"Hello", b"Hello")57def test_Branch_add():58 l = Leaf(b"Hello", b"Hello")59 store = {l.identity() : l}60 b = l.add(store, b"World", b"World")61 b2 = b.add(store, b"Doom", b"Doom")62 assert isinstance(b2, Branch)63 assert b2.left_branch in store64 assert b2.right_branch in store65 assert b2.identity() in store66 b2.check(store)67def test_add_like_a_monkey():68 root = Leaf(b"Hello",b"Hello")69 store = {root.identity() : root}70 from os import urandom71 for _ in range(100):72 item = urandom(32)73 root = root.add(store, item, item)74 root.check(store)75 assert root.is_in(store, item, item)76def test_Leaf_add():77 l = Leaf(b"Hello", b"Hello")78 store = {l.identity() : l}79 b = l.add(store, b"World", b"World")80 assert isinstance(b, Branch)81 assert b.left_branch in store82 assert b.right_branch in store83 assert b.identity() in store84 assert store[b.left_branch].item <= b.pivot85 assert store[b.right_branch].item > b.pivot86def test_Tree():87 t = Tree()88def test_add_isin():89 t = Tree()90 # Test positive case91 t.add(b"Hello")92 assert t.is_in(b"Hello") == True93 # Infix operator94 assert b"Hello" in t95def test_fail_isin():96 t = Tree()97 # Test negative case98 assert t.is_in(b"World") == False99def test_massive():100 t = Tree()101 from os import urandom102 for _ in range(100):103 item = urandom(32)104 t.add(item)105 assert t.is_in(item)106 assert not t.is_in(urandom(32))107def test_multi_add():108 t = Tree()109 from os import urandom110 X = [urandom(32) for _ in range(100)]111 t.multi_add(X)112 for x in X:113 assert x in t114 X = [urandom(32) for _ in range(100)]115 t.multi_add(X)116 for x in X:117 assert x in t118 Y = [urandom(32) for _ in range(100)]119 for y in Y:120 assert y not in t121def test_multi_small():122 t = Tree()123 t.multi_add([b"Hello", b"World"])124 assert b"Hello" in t125 assert b"World" in t126 t.multi_add([b"A", b"B", b"C", b"D", b"E", b"F"])127 assert b"E" in t128 assert b"F" in t129def test_multi_test():130 t = Tree()131 t.multi_add([b"Hello", b"World"])132 assert t.multi_is_in([b"Hello", b"World"]) == [True, True]133 answer, head, evidence = t.multi_is_in([b"Hello", b"World"], evidence=True)134 assert answer == [True, True]135 e = dict((k.identity(), k) for k in evidence)136 t2 = Tree(e, head)137 assert t2.multi_is_in([b"Hello", b"World"]) == [True, True]138def test_lookup():139 l = Leaf(item=b"Hello", key=b"A")140 store = {l.identity() : l}141 b = l.add(store, item=b"World", key=b"B")142 assert b.is_in(store, b"Hello", b"A")143 assert b.is_in(store, b"World", b"B")144 assert not b.is_in(store, b"World", b"C")145 assert b.lookup(store, b"B") == (b"B", b"World")146 try:147 b.lookup(store, b"B") == (b"B", b"World2")148 assert False149 except:150 assert True151 try:152 b.lookup(store, b"C") == (b"B", b"World2")153 assert False154 except:155 assert True156def test_double_add():157 l = Leaf(item=b"Hello", key=b"A")158 store = {l.identity() : l}159 b = l.add(store, item=b"World", key=b"B")160 assert b.is_in(store, b"Hello", b"A")161 assert b.is_in(store, b"World", b"B")162 assert not b.is_in(store, b"World", b"C")163 b = b.add(store, item=b"World2", key=b"B")164 assert b.lookup(store, b"B") == (b"B", b"World")165 assert not b.lookup(store, b"B") == (b"B", b"World2")166def test_tree_default_store():167 t = Tree()168 t.multi_add([b"test"])169 assert t.is_in(b"test")170 t2 = Tree()171 assert not t2.is_in(b"test")172def test_tree_empty_store():173 store = {}174 t = Tree(store)175 t.multi_add([b"test"])176 assert t.is_in(b"test")177 t2 = Tree(store, root_hash=t.root())...
test_build.py
Source:test_build.py
...7import pytest8this_folder = op.dirname(op.abspath(__file__))9sys.path.append(op.join(this_folder, '..'))10from jupyterbook.utils import _split_yaml11def is_in(lines, check):12 is_in = False13 for line in lines:14 if check in line:15 is_in = True16 return is_in17def is_not_in(lines, check):18 is_in = True19 for line in lines:20 if check in line:21 is_in = False22 return is_in23def replace_in_file(from_text, to_text, filename):24 with open(filename, "r") as sources:25 lines = sources.readlines()26 with open(filename, "w") as sources:27 for line in lines:28 sources.write(line.replace(from_text, to_text))29####################################################30# Delete old build and create a new one31curdir = op.dirname(op.abspath(__file__))32if op.isdir(op.join(curdir, 'site', '_build')):33 sh.rmtree(op.join(curdir, 'site', '_build'))34print("Building site for test suite...")35cmd = ["python", op.join(curdir, "..", "generate_book.py"),36 "--site-root", op.join(curdir, "site"), "--path-template", op.join(curdir, "..", "templates", "jekyllmd.tpl")]37out = subprocess.check_call(cmd)38####################################################39# Check outputs40def test_notebook():41 with open(op.join(curdir, 'site', '_build', 'tests', 'notebooks.md'), 'r') as ff:42 lines = ff.readlines()43 # Escaping characters get doubled44 assert is_in(lines, "\\\\$Escape \\\\$your \\\\$dollar signs!")45 # Notebook-converted images work46 assert is_in(lines, "../images/tests/notebooks_2_0.png")47 # Jekyll markdown classes are there48 assert is_in(lines, "{:.input_area}")49 # Cell hiding etc works50 assert is_not_in(lines, 'thisvariable = "none of this should show up in the textbook"')51 assert is_not_in(lines, '"this plot *will* show up in the textbook."')52 # Static files are copied over53 assert op.exists(op.join(curdir, 'site', '_build', 'tests', 'cool.jpg'))54def test_split_yaml():55 with open(op.join(curdir, 'site', '_build', 'tests', 'features.md'), 'r') as ff:56 lines = ff.readlines()57 # Make sure the yaml remains in the file58 assert is_in(lines, "yaml_frontmatter: true")59 # Edgecases etc on the splitter function60 assert _split_yaml([]) == ([], [])61 assert _split_yaml(['foo\n', 'bar\n']) == ([], ['foo\n', 'bar\n'])62 assert _split_yaml(['---\n', 'foo\n', 'bar\n']) == ([], ['---\n', 'foo\n', 'bar\n'])63 exp = ['---\n', 'foo\n', '---\n']64 assert _split_yaml(exp) == (['foo\n'], [])65 assert (_split_yaml(['---\n', 'foo\n', '---\n', 'baz\n', 'barf\n']) ==66 (['foo\n'], ['baz\n', 'barf\n']))67 assert (_split_yaml(['---\n', 'foo\n', 'bar\n', '---\n', 'baz\n', 'barf\n']) ==68 (['foo\n', 'bar\n'], ['baz\n', 'barf\n']))69 assert (_split_yaml(['\n', '\n', '---\n', 'foo\n', '---\n', 'baz\n', 'barf\n']) ==70 (['foo\n'], ['baz\n', 'barf\n']))71 assert (_split_yaml([' \n', ' \n', '---\n', 'foo\n', '---\n', 'baz\n', 'barf\n']) ==72 (['foo\n'], ['baz\n', 'barf\n']))73def test_notebook_update():74 source_file = op.join(curdir, 'site', 'content', 'tests', 'features.md')75 target_file = op.join(curdir, 'site', '_build', 'tests', 'features.md')76 source_text = 'https://'77 target_text = 'www.'78 # replace source_text with target_text in source_file79 assert is_not_in(open(target_file).readlines(), target_text)80 replace_in_file(source_text, target_text, source_file)81 out = subprocess.check_call(cmd)82 assert is_in(open(target_file).readlines(), target_text)83 replace_in_file(target_text, source_text, source_file)84 out = subprocess.check_call(cmd)...
ABC157B.py
Source:ABC157B.py
1from collections import defaultdict2def main():3 def is_in(a, b):4 return (a, b) in nums_points5 flag = 06 mat = [7 list(map(int, input().split())),8 list(map(int, input().split())),9 list(map(int, input().split()))10 ]11 n = int(input())12 nums = [int(input()) for i in range(n)]13 combs = defaultdict(int)14 for i in range(3):15 for j in range(3):16 combs[mat[i][j]] = (i, j)17 nums_points = []18 for n in nums:19 nums_points.append(combs[n])20 if is_in(0, 0) and is_in(0, 1) and is_in(0, 2):21 flag += 122 if is_in(1, 0) and is_in(1, 1) and is_in(1, 2):23 flag += 124 if is_in(2, 0) and is_in(2, 1) and is_in(2, 2):25 flag += 126 if is_in(0, 0) and is_in(1, 0) and is_in(2, 0):27 flag += 128 if is_in(0, 1) and is_in(1, 1) and is_in(2, 1):29 flag += 130 if is_in(0, 2) and is_in(1, 2) and is_in(2, 2):31 flag += 132 if is_in(0, 0) and is_in(1, 1) and is_in(2, 2):33 flag += 134 if is_in(0, 2) and is_in(1, 1) and is_in(2, 0):35 flag += 136 if flag:37 print("Yes")38 else:39 print("No")40if __name__ == "__main__":...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!