# def sum_num(s): # summa = 0 # for i in s: # if i.isdigit(): # summa += int(i) # print(summa) # sum_num('asd12312asdf') #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # def get_body_mass_index(weight, height): # index = weight/((height*0.01)**2) # if index < 18.5: # print('Недостаточная масса тела') # elif 18.5 <= index <= 25.0: # print('Норма') # else: # print('Избыточная масса тела') # get_body_mass_index(70, 170) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # def check_password(psw): # f1 = False # digit_cnt = 0 # cap = False # sim = False # for i in psw: # if i.isdigit(): # digit_cnt += 1 # if i.istitle(): # cap = True # if i in "!@#$%": # sim = True # if (digit_cnt >= 3) and cap == True and sim == True and len(psw) >= 10: # print('Perfect password') # else: # print('Easy peasy') #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # def count_letters(s): # cap_cnt = 0 # uncap_cnt = 0 # for i in s: # if i.isalpha(): # if i.istitle(): # cap_cnt += 1 # else: # uncap_cnt += 1 # print('Количество заглавных символов:', cap_cnt) # print('Количество строчных символов:', uncap_cnt) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # def foo(): # print('function foo') # a = foo() # print(a) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # def find_duplicate(lst): # my_list = [] # new_l = [] # for i in lst: # if i not in my_list: # my_list.append(i) # for i in my_list: # if lst.count(i) > 1: # new_l.append(i) # return new_l # print(find_duplicate([1, 1, 1, 1, 1, 2, 2, 2, 2])) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def first_unique_char(s): s.lower() for i in range(len(s)): if s.count(s[i]) == 1: return i else: return -1 # print(first_unique_char('aasssddddddddq')) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def format_name_list(names: list): length = len(names) s = "" if length == 0: return "" elif length == 1: return names[0].get("name") elif length == 2: return names[0].get("name") + ' и ' + names[1].get("name") else: for i in range(len(names) - 1): s += names[i].get("name") + ', ' return s[:-2] + " и " + names[-1].get("name") # print(format_name_list([{'name': 'Bart'}, {'name': 'Lisa'}, {'name': 'Maggie'}, # {'name': 'Homer'}, {'name': 'Marge'}])) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def get_domain_name(url : str): my_list = [] if url.find("//") != -1: my_list = url.split("//") if my_list[1].find("www") != -1: my_list = my_list[1].split(".") return my_list[1] else: my_list = my_list[1].split(".") return my_list[0] else: my_list = url.split(".") return my_list[1] # assert get_domain_name("http://google.com") == "google" # assert get_domain_name("http://google.co.jp") == "google" # assert get_domain_name("www.xakep.ru") == "xakep" # assert get_domain_name("https://youtube.com") == "youtube" # assert get_domain_name("http://github.com/carbonfive/raygun") =='github' # assert get_domain_name("http://www.zombie-bites.com") == 'zombie-bites' # assert get_domain_name("https://www.siemens.com") == 'siemens' # assert get_domain_name("https://www.whatsapp.com") == 'whatsapp' # assert get_domain_name("https://www.mywww.com") == 'mywww' # print('Проверки пройдены') #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def factorial(n): fact = 1 for num in range(2, n + 1): fact *= num return fact def trailing_zeros(n): s = str(factorial(n))[::-1] l = [] for i in range(len(s)): if s[i] != '0': break else: l.append(s[i]) return len(l) # assert trailing_zeros(0) == 0 # assert trailing_zeros(6) == 1 # assert trailing_zeros(30) == 7 # assert trailing_zeros(12) == 2 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def count_AGTC(dna): return dna.count('A'), dna.count('G'), dna.count('T'), dna.count('C') # assert count_AGTC('AGGTC') == (1, 2, 1, 1) # assert count_AGTC('AAAATTT') == (4, 0, 3, 0) # assert count_AGTC('AGTTTTT') == (1, 1, 5, 0) # assert count_AGTC('CCT') == (0, 0, 1, 2) # print('Проверки пройдены') #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def foo(): "Эта функция делает что-то" pass # print(foo.__doc__) class Model: """ This is class model """ pass # help(Model) # print(Model.__doc__) def get_even(lst, number): """_summary_ Args: lst (_type_): _description_ number (_type_): _description_ """ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # first : int = 100 def add_numbers(a: int, b: int | float | str) -> int: return a + b # print(add_numbers.__annotations__) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from typing import List, Dict, Tuple, Optional, Any, Union def list_upper(lst: List[str]): for elem in lst: print(elem.upper()) # e: Any = 12 # e = "sdfsdf" #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def first_repeated_word(s: str): """Находит первый дубль в строке Args: s (str): строка Returns: str: первое повторяющееся слово """ l = s.split() d_index = dict() for i in range(len(l)): if (l.count(l[i]) > 1) and l[i] not in d_index.values(): d_index.update({l.index(l[i], i+1, len(l)) : l[i]}) if len(d_index) == 0: return None m = len(l) if m == 0: return None for key,value in d_index.items(): if key < m: m = key return d_index.get(m) assert first_repeated_word("ab ca bc ab") == "ab" assert first_repeated_word("ab ca bc Ab cA aB bc") == "bc" assert first_repeated_word("ab ca bc ca ab bc") == "ca" assert first_repeated_word("hello hi hello") == "hello" print(first_repeated_word.__doc__)