This file contains hidden or 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
# ok | |
def create_person(*args): | |
first_name, last_name, age = args | |
return { | |
'First Name': first_name, | |
'Last Name': last_name, | |
'Age': age | |
} | |
# Caller assumes the order: first name, last name, age. |
This file contains hidden or 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 urllib.parse import urlparse | |
from bs4 import BeautifulSoup | |
import httpx | |
API_URL = "https://codechalleng.es/api/articles/" | |
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" | |
HEADERS = {"User-Agent": USER_AGENT} | |
PYBITES_DOMAINS = ("pybit.es",) |
This file contains hidden or 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 random | |
import pytest | |
from script import get_random_emails | |
@pytest.fixture(autouse=True) | |
def set_random_seed(): | |
random.seed(123) |
This file contains hidden or 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 csv | |
import random | |
DATA = "MOCK_DATA.csv" | |
def get_emails(data=DATA): | |
with open(data) as f: | |
reader = csv.reader(f) | |
next(reader) |
This file contains hidden or 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
>>> class Dog: | |
... def __init__(self, breed, color): | |
... self.breed = breed | |
... self.color = color | |
... | |
>>> dog1 = Dog("bulldog", "brown") | |
>>> | |
>>> dog1 | |
<__main__.Dog object at 0x7fe114d36580> | |
>>> dog1.attr |
This file contains hidden or 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 ast | |
from pathlib import Path | |
import sys | |
def check_for_else_in_module(module_path): | |
with open(module_path, "r") as file: | |
try: | |
tree = ast.parse(file.read()) | |
except SyntaxError: |
This file contains hidden or 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, sleep | |
def timing(f): | |
"""A simple timer decorator""" | |
@wraps(f) | |
def wrapper(*args, **kwargs): | |
start = time() | |
result = f(*args, **kwargs) | |
end = time() |
This file contains hidden or 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 functools | |
@functools.cache | |
def fib(n): | |
if n < 2: | |
return n | |
return fib(n-1) + fib(n-2) | |
fib(35) |
This file contains hidden or 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. save time == | |
alias python3=python3.11 | |
alias ae='source venv/bin/activate' | |
alias pvenv='python3 -m venv venv && ae' | |
alias pipall="python -m pip install -r requirements.txt" | |
alias pipfr="python -m pip freeze >|requirements.txt" | |
alias dl='cd ~/Downloads' |
This file contains hidden or 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 pprint import pprint as pp | |
import random | |
import requests | |
def get_random_tip(): | |
url = "https://codechalleng.es/api/pytips/" | |
response = requests.get(url) |