Skip to content

Instantly share code, notes, and snippets.

def isPP(n):
"""Your task is to check wheter a given integer is a perfect power. If it is a perfect power, return a pair m and
k with mk = n as a proof. Otherwise return Nothing, Nil, null, NULL, None or your language's equivalent.
Read more - https://bit.ly/37mivH7"""
numbers = set()
for i in range(1, 120): # Generating a list of base of power
for j in range(2, 15): # Generating a list of index power
numbers.add(pow(i, j)) # Adding created numbers into a set
@kurzweil777
kurzweil777 / Title Case
Created June 14, 2020 08:04
Exercise from code_wars
def title_case(title, minor_words=''):
"""Write a function that will convert a string into title case, given an optional list of exceptions (minor
words). The list of minor words will be given as a string with each word separated by a space. Your function
should ignore the case of the minor words string -- it should behave in the same way even if the case of the
minor word string is changed. """
words = []
minor_words = minor_words.lower().split()
for word in title.lower().split():
@kurzweil777
kurzweil777 / Domain_Name
Last active June 14, 2020 16:13
Exercise from code_wars
import re
def domain_name(url):
"""Write a function that when given a URL as a string, parses out just the domain name and returns it as a
string. """
# Creating a Regular expression to search a website
regex = re.compile(r"""(http://www.|https://www.|www.|http://|https://)?(.*)\.""")
# Writing down matches into result variable and splitting them into groups
result = regex.match(url).group(2).split(".")
@kurzweil777
kurzweil777 / How many word?
Last active June 18, 2020 05:47
Exercise from Code_Wars
def testit(s):
"""How many times do you find the 'word' in a given string?
More info : https://bit.ly/30KCAWx"""
matches = []
count = 0
letters = ['w', 'o', 'r', 'd']
for word in s.lower():
if word not in matches:
matches.append(word)
try: # Using try/except block to avoid problems with indexes
@kurzweil777
kurzweil777 / PokeScan
Created June 18, 2020 11:43
Exercise from code_wars
class PokeScan:
"""The task: https://bit.ly/3hycrA2"""
characters = {"water": "wet", "fire": "fiery", "grass": "grassy"}
def __init__(self, name, level, pkmntype):
self.name = name
self.level = level
self.pkmntype = pkmntype
if level in range(0, 21) or level < 0:
self.level_character = "weak"
@kurzweil777
kurzweil777 / Change the name of class
Created June 18, 2020 16:39
Exercise from code_wars
class MyClass:
pass
def class_name_changer(cls, new_name):
"""The task: https://bit.ly/2UWVJAE"""
if new_name.isalnum() and new_name[0].isupper():
cls.__name__ = new_name
return new_name
@kurzweil777
kurzweil777 / First Decorators
Created June 21, 2020 16:34
Exercise from Py_Course
# Create an @authenticated decorator that only allows the function to run is user1 has 'valid' set to True:
user1 = {
'name': 'Sorna',
'valid': True # changing this will either run or not run the message_friends function.
}
def authenticated(fn):
def check(*args, **kwargs):
if dict(*args).get('valid'):
@kurzweil777
kurzweil777 / +1 Array
Created June 22, 2020 04:43
Exercise from code_wars
import re
def up_array(arr):
"""Given an array of integers of any length, return an array that has 1 added to the value represented by the
array. More info: https://bit.ly/3elEzV2"""
if len(list(None for number in arr if number < 0 or number not in range(0, 10) or len(arr) < 1)) > 0:
return None
elif len(arr) < 1:
return None
import requests
from bs4 import BeautifulSoup
import pprint
"""This Parser returns Title, Link and a price. Additional functions will be included in a future"""
URL = "https://www.olx.ua/elektronika/kompyutery-i-komplektuyuschie/"
HEADERS = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.191', 'accept': '*/*'}
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Lorem ipsum</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="description" content="Your lorem ipsum">
<meta name=keyword" content="Lorem, ipsum">
</head>
<body>