Skip to content

Instantly share code, notes, and snippets.

View pysoftware's full-sized avatar
👨‍💻
300КК В СЕКУ

Дмитрий pysoftware

👨‍💻
300КК В СЕКУ
  • https://novator-it.com/
  • Russia, Moscow
View GitHub Profile
@pysoftware
pysoftware / fake_useragent.py
Last active February 14, 2019 18:02
Fake user agent
from fake_useragent import UserAgent
def get_html(url):
response = requests.get(url, headers={'User-Agent': UserAgent().chrome})
return response.text
# Результат UserAgent().chrome:
# 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.15 (KHTML, like Gecko) Chrome/24.0.1295.0 Safari/537.15'
@pysoftware
pysoftware / checkprogramtime.py
Created February 14, 2019 18:05
Check program time
from time import time
# Time before running program
start = time()
# for i ...: ...
# Time after program done
print('Time', time() - start)
@pysoftware
pysoftware / gcd.py
Last active February 14, 2019 18:54
GCD/ НОД
# Greatest common divisor
# Наибольший общий делитель
a, b = 16, 17
while b != 0:
# temp = a
# a = b
# b = temp % b
a, b = b, a%b
print(a)
@pysoftware
pysoftware / selection_sort.py
Created February 14, 2019 18:13
Selection sort/ Сортировка выбором
# Selection sort alghorirm
# Алгоритм сортировки выбором
a = [3, 5, 1, 0, 2, 8]
for j in range(1,len(a)):
i = j-1
while i >= 0 and a[i] > a[i+1]:
a[i], a[i+1] = a[i+1], a[i]
i -= 1
@pysoftware
pysoftware / reverse_string.py
Last active February 16, 2019 07:22
Reverse string
# Reverse a string/ Переворот строки
a = 'Hello world!'
# 1 way
a = a[::-1]# Result: !dlrow olleH
# 2 way
reversed_string = ''
for i in a:
reversed_string += i# Result: !dlrow olleH
# 3 way
@pysoftware
pysoftware / factorial.py
Last active March 14, 2019 05:19
Factorial
# Factorial/ Факториал
def factorial(num):
if num <= 1: return 1
return num * factorial(num-1)
@pysoftware
pysoftware / binary_search.py
Created February 19, 2019 14:55
Binary search
# Binary search/ бинарная сортировка
def binary_search(list, item):
# В переменных low и high хранятся
# границы той части списка, в которой
# выполняется поиск
low = 0
high = len(list) - 1
i = 0
while low <= high:
@pysoftware
pysoftware / fast_power.py
Last active March 17, 2019 07:01
Recursion exponentiation/ Рекусивное воезведение в степень
# Recursion exponentiation
# Рекурсивное возведение в степень
def fast_power(a,b):
# Базовый случай
if b == 0: return 1
if b % 2 == 1:
return a * fast_power(a, b-1)
else:
return fast_power(a*a, b//2)
@pysoftware
pysoftware / fibonacci.py
Created February 20, 2019 14:18
Fibonacci/ Числа фибоначи
# Fibonacci recursion
# Рекурсия чисел фибоначи
def fib(a):
# Базовый случай
if a <= 1: return a
else: return fib(a - 1) + fib(a - 2)
print(fib(int(input())))
@pysoftware
pysoftware / recursive_sum.py
Last active March 17, 2019 05:54
Recursive sum
'''N IS REQUIRED PARAMETЕR'''
def recursive_sum1(arr, n):
n -= 1
if n < 0:
return 0
return arr[n] + recursive_sum1(arr, n)
def recursive_sum2(arr, n):
# n - value of numbers
if n == len(arr):
return 0