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
{ | |
"basics": { | |
"name": "Jarosław Piszczała", | |
"label": "Python Developer", | |
"email": "[email protected]", | |
"url": "https://piszczala.pl/", | |
"location": { | |
"countryCode": "PL", | |
"address": "Poland", | |
"city": "Częstochowa" |
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 random | |
class Deck: | |
def __init__(self, cards): | |
self.cards = cards | |
def get_deck(self): | |
""" | |
Returns the deck 'updated', after shuffling it. | |
""" |
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
sentence = "Words like herself and researcher also get censored but only her, should her." | |
new_words = [] | |
for word in sentence.split(): | |
if word.replace(',', "").replace('.', "") == 'her': | |
word = '***'+word[3:] | |
new_words.append(word) | |
new_sentence = " ".join(new_words) | |
print(new_sentence) |
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
""" | |
Write a function that will sort a nested dictionary. | |
If there is list of dicts, sort by 'buzz' key | |
Extra: | |
- Make sorting list of dicts easy to extend | |
- Add rules to not sort some lists | |
For example: |
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 time import process_time | |
def primes(num): | |
def prim(n): | |
return len([i for i in range(2, n) if n % i == 0]) == 0 | |
return [i for i in range(2, num) if prim(i)] | |
def prim(num): |
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 print_fifth_element(iterable): | |
passed = False | |
try: | |
print(iterable[4]) | |
passed = True | |
except IndexError: | |
iterable.append(iterable[-1]) | |
except TypeError: | |
iterable = [iterable] | |
except KeyError as e: |
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
class GarageException(Exception): | |
"""Garage exceptions base""" | |
class NoSpaceAvailableError(GarageException): | |
"""Raises when no space available in garage""" | |
class Vehicle: | |
size = 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
from functools import lru_cache | |
@lru_cache(128) | |
def fibonaci(n): | |
if n > 2: | |
return fibonaci(n-1) + fibonaci(n-2) | |
if 0 < n <= 2: | |
return 1 | |
if n == 0: | |
return 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
def str_to_ascii(s): | |
chars_to_ascii = [ord(e) for e in s] | |
reversed_ascii = chars_to_ascii[::-1] #or reversed(chars_to_ascii) | |
map_to_str = map(lambda x:str(x), reversed_ascii) #wymagane przez join aby kady element był stringiem | |
return "".join(map_to_str) | |
def ascii_to_str(s): | |
result = "" | |
while s: #póki nie przetworzymy wszystkiego | |
number_length = 3 if s[0]=='1' else 2 #sprawdzamy czy będzie cyfra 1XX czy 3X, 6-9X |
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
""" | |
Change filenames for Xiaomi 3S files to format 'yyyy-mm-dd hh-mm-ss' | |
""" | |
import re | |
import os | |
def get_new_filename(filename): | |
result = re.search("\w*_(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})(?:_\w*?)\.(\w*)", filename) | |
if result: |
NewerOlder