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 timeit import timeit | |
print("list() = ", timeit("list()")) | |
print("[]", timeit("[]")) | |
my_list = list() | |
my_second_list = [] | |
my_dict = dict() | |
my_second_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
# 1. Дан список строк my_list. Создать новый список в который поместить | |
# элементы из my_list по следующему правилу: | |
# Если строка стоит на нечетном месте в my_list, то ее заменить на | |
# перевернутую строку. "qwe" на "ewq". | |
# Если на четном - оставить без изменения. | |
# Задание сделать с использованием enumerate или range. | |
my_list = ["Это", "просто", "пример", "списка", "123", "456"] | |
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
# 1. Написать функцию, которая получает в виде параметра имя файла названия | |
# интернет доменов (domains.txt) | |
# и возвращает их в виде списка строк (названия возвращать без точки). | |
def get_domains(filename): | |
""" | |
Функция возвращает название интернет доменов | |
:param filename: строка с именем файла | |
:return: список |
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)) |
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
# 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
# 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
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
# Напишите функцию для создания файла и записи в него случайных чисел, | |
# каждое число записывается в файл через пробел, но не больше 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
# 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'}, | |
] |
OlderNewer