Skip to content

Instantly share code, notes, and snippets.

@kurzweil777
kurzweil777 / exercise1_from_book
Last active May 20, 2020 07:28
Regular Expressions
import re
# Задание: https://ibb.co/NKprbMW
number = ("42\n"
"1,234\n"
"6,368,745\n"
"12,34,567\n"
"1234")
numberRegex = re.compile(r'''^\d{1,3},\d{3},\d{3}|^\d{1,3},\d{3}|^\d{1,3}$''', re.MULTILINE)
@kurzweil777
kurzweil777 / exercise2_from_book
Created May 20, 2020 07:31
Regular Expressions
#Задание - https://ibb.co/54s5xwy
import re
names = ("Satoshi Nakamoto\n"
"Alice Nakamoto\n"
"RoboCop Nakamoto\n"
"satoshi Nakamoto\n"
"Mr. Nakamoto\n"
"Nakamoto\n"
@kurzweil777
kurzweil777 / exercise3_from_book
Last active May 20, 2020 07:47
Regular Expressions
import re
phrases = ("Alice eats apples.\n"
"Bob pets cats.\n"
"Carol throws baseballs.\n"
"Alice throws Apples.\n"
"BOB EATS CATS.\n"
"RoboCop eats apples.\n"
"ALICE THROWS FOOTBALLS.\n"
"Carol eats 7 cats.")
@kurzweil777
kurzweil777 / exercise4_from_book
Created May 20, 2020 13:52
Regular Expressions
import re
def strong_pass(your_pass):
passRegex1 = re.compile(r'''[A-Z]''') # Проверяем наличие больших букв
passRegex2 = re.compile(r'''[a-z]''') # Проверяем наличие маленьких букв
passRegex3 = re.compile(r'''\d''') # Проверяем наличие цифр
result = passRegex1.search(your_pass)
result2 = passRegex2.search(your_pass)
result3 = passRegex3.search(your_pass)
@kurzweil777
kurzweil777 / exercise1_from_coursera
Created May 27, 2020 07:46
First Attempts in OOP
class Animal:
name = ""
category = ""
def __init__(self, name):
self.name = name
def set_category(self, category):
self.category = category
@kurzweil777
kurzweil777 / exercise2_from_book
Created May 27, 2020 12:03
First Attempts in OOP
import random
class Server:
def __init__(self):
"""Creates a new server instance, with no active connections."""
self.connections = {}
def add_connection(self, connection_id):
"""Adds a new connection to this server."""
import string
import re
def alphabet_position(text):
"""This function replaces every letter with its position in the
alphabet."""
alphabet = (dict(enumerate(string.ascii_lowercase))) # Creating a dictionary with alphabet
alphabet_updated = {value: key + 1 for key, value in alphabet.items()} # Swapping keys and values
lower_text = text.lower()
@kurzweil777
kurzweil777 / Highest and Lowest
Created June 1, 2020 10:07
Exercise_from_CodeWars
def high_and_low(numbers):
"""In this little assignment you are given a string of space separated numbers, and have to return the highest
and lowest number. """
int_numbers = [] # Creating a list for inputting integers
for number in numbers.split(): # Iteration through the string with numbers
int_numbers.append(int(number)) # Writing integers into a created list
new_numbers = sorted(int_numbers) # Sorting numbers
return str(new_numbers[-1]) + " " + str(new_numbers[0]) # Returning the result
@kurzweil777
kurzweil777 / Get Sum
Created June 1, 2020 11:14
Exercise_from_CodeWars
def get_sum(a, b):
"""Given two integers a and b, which can be positive or negative, find the sum of all the numbers between
including them too and return it. If the two numbers are equal return a or b. """
if a > b: # Range function won't work if a > b, so we replacing them by each other
new_a = b
new_b = a
return sum(list(range(new_a, new_b + 1))) # Returning a sum number of all numbers in range from a to b
elif a == b:
return a | b # Returning of a or b, if numbers are equal
else:
@kurzweil777
kurzweil777 / IQ Test
Created June 3, 2020 12:29
Exercise_from_CodeWars
def iq_test(numbers):
"""Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given
numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help
Bob — to check his answers, he needs a program that among the given numbers finds one that is different in
evenness, and return a position of this number. """
all_numbers: list = [] # Creating a list to save all odd and even values
odd_count: int = 0 # Creating an int to count an odd value
even_count: int = 0 # Creating an int to count an even value