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
# bad | |
user = {"first_name": "John", "last_name": "Doe"} | |
full_name = f"{user['first_name']} {user['last_name']}" | |
# better | |
class User: | |
def __init__(self, first_name, last_name): | |
self.first_name = first_name |
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
# pip install prettytable | |
from prettytable import PrettyTable | |
resultTable = PrettyTable() | |
class Homework: | |
def __init__(self, name, description, complexity, status): | |
self.name = name | |
self.description = description |
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
# Разобраться в коде unit_test_framework.py | |
# Напишете интерактивный калькулятор. | |
# Предполагается, что пользовательский ввод представляет собой формулу, | |
# состоящую из числа, оператора (как минимум + и -) и другого числа, | |
# разделенных пробелом (например, 1 + 1). Используйте str.split () | |
# Если входные данные не состоят из 3 элементов, генерируйте эксепшн FormulaError. | |
# Попробуйте преобразовать первый и третий элемент в float | |
# ( float_value = float(str_value)). | |
# Поймайте любую возникающую ValueError и сгенерируйте вместо него FormulaError | |
# Если второй элемент не является «+» или «-», киньте эксепшн FormulaError |
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
# list of dictionaries search | |
text_list = [ | |
{'number': 1, 'notes': 'ToDO1'}, | |
{'number': 2, 'notes': 'ToDO2'}, | |
{'number': 3, 'notes': 'ToDO3'}, | |
{'number': 4, 'notes': 'ToDO4'}, | |
{'number': 5, 'notes': 'ToDO5'}, | |
{'number': 6, 'notes': 'ToDO6'}, | |
] |
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
# Напишите функцию для создания файла и записи в него случайных чисел, | |
# каждое число записывается в файл через пробел, но не больше 10ти чисел в строку. | |
# Всего случайных чисел должно быть 1000 | |
import random | |
def create_and_write(filename): | |
with open(f"{filename}.txt", "w") as file: | |
strings = [] | |
for _ in range(100): |
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
my_dict = {1: 'way', 2: 'apple'} | |
my_dict_2 = {1: 'way', 'value': 'apple'} | |
my_tuple = (1, 2, 3) | |
new_dict = dict([(1, 'way'), (2, 'apple')]) | |
student = { | |
'name': 'Bob', | |
'age': 20, |
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
# 3) У вас есть список my_list с значениями типа int. | |
# Если в my_list количество элементов меньше 2, то в конец добавить значение 0. | |
# Если количество элементов больше или равно 2, то добавить сумму | |
# последних двух элементов. | |
# Количество элементов в списке можно получить с помощью функции len(my_list) | |
my_list = [1, 2, 3, 5, 6] | |
if len(my_list) >= 2: |
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
# map | |
import operator | |
from functools import reduce | |
item = [1, 2, 3, 4] | |
squared = [] | |
for i in item: | |
squared.append(i ** 2) | |
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 sys import setrecursionlimit | |
maze = [ | |
['#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'], # 0 | |
['#', '#', '#', '#', '#', '#', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '#', '#', '#'], # 1 | |
['#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '#', '#', '#', '#', '#', '#', '.', '#', '#', '#'], # 2 | |
['#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '#', '#', '#', '.', '.', '.', '.', '#', '#', '#'], # 3 | |
['#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '.', '#', '#', '.', '#', '#', '#'], # 4 | |
['#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '#', '#', '#'], # 5 | |
['#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '#', '#', '#'], # 6 |
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 re | |
text = "платеж номер платеж" | |
result = re.match(r"платеж", text) # вернули первое вхождение | |
# print(result.group(0)) | |
result = re.search(r"номер", text) # имеет смысл искать | |
# print(result.group(0)) |
NewerOlder