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 requests | |
import re | |
def extract_links(url): | |
r = requests.get(url) | |
links = re.findall(r'href="(.*?)"', r.text, flags=re.IGNORECASE) | |
return links | |
# print(extract_links('https://habrahabr.ru/')) |
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 functools import wraps | |
from time import time | |
def cancelled(func): | |
"""Cancels the execution of a function""" | |
@wraps(func) | |
def wrapped(*args, **kwargs): | |
print(func.__name__, 'is cancelled!') | |
return wrapped |
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 random import choice | |
class Animal: | |
def __init__(self): | |
self.species = choice(['those that belong to the emperor', | |
'predators', 'venomous', 'poisonous', | |
'snappish', 'vegetarian', 'fluffy', | |
'domestic', 'those that, at a distance, resemble flies']) |
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
# -*- coding: utf-8 -*- | |
import random | |
import sys | |
NOUGHT = 'O' | |
CROSS = 'X' | |
EMPTY_SLOT = '_' | |
MOVES = [str(x) for x in range(1, 10)] | |
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
# -*- coding: utf-8 -*- | |
# `random` module is used to shuffle field, see§: | |
# https://docs.python.org/3/library/random.html#random.shuffle | |
import random | |
import sys | |
# Empty tile, there's only one empty cell on a field: | |
EMPTY_MARK = 'x' |
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
# Написать функцию, которая принимает любое количество аргументов чисел. | |
# Среди них она находит максимальное и минимальное. И возвращает оба | |
def max_and_min(*arg): | |
return sorted(arg)[-1], sorted(arg)[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
# 1 | |
mylist = [2, 54345, 55**5, 63**.5, 3.1415926, 10, 111111] | |
sorted(mylist) | |
# 2 | |
d = {} | |
for i in range(22, 99, 11): | |
d[i] = str(i) | |
print(d.get(i), d[i]) |
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
questions_pull = [ | |
'What is a name of a interpreted programming language, created by Guido van Rossum, which philosophy emphasizes code readability?', | |
'All the next questions are by chance related to Python as well. So, what is a statement which executes a block of code as long as its condition is true?', | |
'What is a boolean operator which returns "False" only if all the operands equal "False"?', | |
'How does the exponentiation operator look?', | |
'From what number does Python start all its indexing?', | |
'What function do we use to try to transform the string to an integer number?', | |
'What function do we use to display some text to a user?', | |
'If we have "print(\'string\'[0])" executed, what do we expect to see?', | |
'What do you think you\'ll see if you execute "print(len(\'7 chars\'))"?', |