Best Python code snippet using yandex-tank
utils.py
Source:utils.py  
1from typing import Optional2from .const import TRADE_DAYS_FILE_PATH3def read_trade_days():4    with open(TRADE_DAYS_FILE_PATH, "r") as f:5        return f.read().split(",")6def parse_out_tencent_tick_dict(msg: str) -> Optional[dict]:7    field_list = msg.split("~")8    try:9        res = {10            "time": field_list[30][8:],11            "name": field_list[1],12            "code": field_list[2],13            "current_price": float(field_list[3]),14            "pre_close": float(field_list[4]),15            "open": float(field_list[5]),16            "high": float(field_list[33]),17            "low": float(field_list[34]),18            "total_amount": float(field_list[37]) * 10000,19            "total_vol": float(field_list[6]) * 100,20            "bid1": float(field_list[9]),21            "bid1_vol": int(field_list[10]) * 100,22            "bid2": float(field_list[11]),23            "bid2_vol": int(field_list[12]) * 100,24            "bid3": float(field_list[13]),25            "bid3_vol": int(field_list[14]) * 100,26            "bid4": float(field_list[15]),27            "bid4_vol": int(field_list[16]) * 100,28            "bid5": float(field_list[17]),29            "bid5_vol": int(field_list[18]) * 100,30            "ask1": float(field_list[19]),31            "ask1_vol": int(field_list[20]) * 100,32            "ask2": float(field_list[21]),33            "ask2_vol": int(field_list[22]) * 100,34            "ask3": float(field_list[23]),35            "ask3_vol": int(field_list[24]) * 100,36            "ask4": float(field_list[25]),37            "ask4_vol": int(field_list[26]) * 100,38            "ask5": float(field_list[27]),39            "ask5_vol": int(field_list[28]) * 100,40            "up_limit": float(field_list[47]),41            "down_limit": float(field_list[48]),42            "price_change": float(field_list[31]),43            "pct_change": float(field_list[32]),44            "flow_market_value": float(field_list[44]),45            "total_market_value": float(field_list[45]),46        }47    except IndexError:48        return None49    return res50def parse_out_sina_tick_dict(msg: str) -> Optional[dict]:51    field_list = msg.split(",")52    try:53        code_name_part = field_list[0].partition('="')54        res = {55            "time": field_list[31].replace(":", ""),56            "name": code_name_part[2],57            "code": code_name_part[0][-6:],58            "current_price": float(field_list[3]),59            "pre_close": float(field_list[2]),60            "open": float(field_list[1]),61            "high": float(field_list[4]),62            "low": float(field_list[5]),63            "total_amount": float(field_list[9]),64            "total_vol": float(field_list[8]),65            "bid1_vol": int(field_list[10]),66            "bid1": float(field_list[11]),67            "bid2_vol": int(field_list[12]),68            "bid2": float(field_list[13]),69            "bid3_vol": int(field_list[14]),70            "bid3": float(field_list[15]),71            "bid4_vol": int(field_list[16]),72            "bid4": float(field_list[17]),73            "bid5_vol": int(field_list[18]),74            "bid5": float(field_list[19]),75            "ask1_vol": int(field_list[20]),76            "ask1": float(field_list[21]),77            "ask2_vol": int(field_list[22]),78            "ask2": float(field_list[23]),79            "ask3_vol": int(field_list[14]),80            "ask3": float(field_list[25]),81            "ask4_vol": int(field_list[16]),82            "ask4": float(field_list[27]),83            "ask5_vol": int(field_list[28]),84            "ask5": float(field_list[29]),85        }86    except IndexError:87        return None88    return res89def exchange_prefix(code: str) -> str:90    return "sh" if code.startswith("6") else "sz"91def format_stock_code(code: str) -> str:92    if code[0].isdigit():93        return exchange_prefix(code) + code94    return code95def format_stock_codes(codes: list) -> list:96    if codes[0][0].isdigit():97        return [exchange_prefix(code) + code for code in codes]98    return codes99def get_day_of_week(year: int, month: int, day: int) -> int:100    """101    0è¡¨ç¤ºæææ¥,1-6表示ææä¸å°ææå
102    """103    if month in (1, 2):104        year -= 1105        month += 12106    return (107        day108        + 2 * month109        + 3 * (month + 1) // 5110        + year111        + year // 4112        - year // 100113        + year // 400114        + 1...tictactoe.py
Source:tictactoe.py  
1def check_win_y():2    check_0 = field_list[0][0] + field_list[1][0] + field_list[2][0]3    check_1 = field_list[0][1] + field_list[1][1] + field_list[2][1]4    check_2 = field_list[0][2] + field_list[1][2] + field_list[2][2]5    if check_0 == win_x or check_1 == win_x or check_2 == win_x:6        print("X wins")7        return True8    elif check_0 == win_o or check_1 == win_o or check_2 == win_o:9        print("O wins")10        return True11def check_win_x():12    check_0 = "".join(field_list[0])13    check_1 = "".join(field_list[1])14    check_2 = "".join(field_list[2])15    if check_0 == win_x or check_1 == win_x or check_2 == win_x:16        print("X wins")17        return True18    elif check_0 == win_o or check_1 == win_o or check_2 == win_o:19        print("O wins")20        return True21def check_win_diagonals():22    check_0 = field_list[0][0] + field_list[1][1] + field_list[2][2]23    check_1 = field_list[0][2] + field_list[1][1] + field_list[2][0]24    if check_1 == win_x or check_0 == win_x:25        print("X wins")26        return True27    elif check_0 == win_o or check_1 == win_o:28        print("O wins")29        return True30win_o = "OOO"31win_x = "XXX"32turn = 133cells_input = " " * 934field_list = [[cells_input[0], cells_input[1], cells_input[2]],35              [cells_input[3], cells_input[4], cells_input[5]],36              [cells_input[6], cells_input[7], cells_input[8]]]37print(f"""---------38| {field_list[0][0]} {field_list[0][1]} {field_list[0][2]} |39| {field_list[1][0]} {field_list[1][1]} {field_list[1][2]} |40| {field_list[2][0]} {field_list[2][1]} {field_list[2][2]} |41---------""")42while True:43    x = input("Enter the coordinates: ")44    y = ""45    def check_input():46        global x, y47        if " " not in x:48            print("You should enter the numbers!")49            return False50        x, y = x.split()51        if not x.isdigit() or not y.isdigit():52            print("You should enter the numbers!")53            return False54        if not 1 <= int(x) <= 3 or not 1 <= int(y) <= 3:55            print("Coordinates should be from 1 to 3!")56            return False57        if "X" in field_list[int(x) - 1][int(y) - 1] or "O" in field_list[int(x) - 1][int(y) - 1]:58            print("This cell is occupied! Choose another one!")59            return False60    if check_input() is False:61        continue62    if turn % 2 == 1:63        field_list[int(x) - 1][int(y) - 1] = "X"64    else:65        field_list[int(x) - 1][int(y) - 1] = "O"66    turn += 167    print(f"""---------68| {field_list[0][0]} {field_list[0][1]} {field_list[0][2]} |69| {field_list[1][0]} {field_list[1][1]} {field_list[1][2]} |70| {field_list[2][0]} {field_list[2][1]} {field_list[2][2]} |71---------""")72    if check_win_x() or check_win_y() or check_win_diagonals():73        break74    if turn == 10:75        print("Draw")...function.py
Source:function.py  
1field_list = [' ',' ',' ',' ',' ',' ',' ',' ',' ']2field = ['1','2','3','4','5','6','7','8','9']3def player1():4    valid = False5    while not valid:6        answer1 = input('What is player O\'s move?')7        if answer1 not in field:8            valid = False9        else:10            valid = True11    field_list[int(answer1) - 1] = 'O'12    print('game status')13    print(field_list[0] + '|' + field_list[1] + '|' + field_list[2] +'\n-----\n'14          + field_list[3] + '|' + field_list[4] + '|' + field_list[5] +'\n-----\n'15          + field_list[6] + '|' + field_list[7] + '|' + field_list[8])16def player2():17    valid = False18    while not valid:19        answer1 = input('What is player X\'s move?')20        if answer1 not in field:21            valid = False22        else:23            valid = True24    field_list[int(answer1) - 1] = 'X'25    print('game status')26    print(field_list[0] + '|' + field_list[1] + '|' + field_list[2] +'\n-----\n'27        + field_list[3] + '|' + field_list[4] + '|' + field_list[5] +'\n-----\n'...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!!
