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 | |
| class MyBaseClass: | |
| def __init__(self, value): | |
| self.value = value | |
| class TimesTwo: | |
| def __init__(self): | |
| self.value *= 2 |
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 os | |
| from threading import Thread | |
| class InputData: | |
| def read(self): | |
| raise NotImplementedError | |
| class PathInputData(InputData): | |
| def __init__(self, path): | |
| super().__init__() |
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
| def safe_division(number, divisor, ignore_overflow, ignore_zero_division): | |
| try: | |
| return number / divisor | |
| except OverflowError: | |
| if ignore_overflow: | |
| return 0 | |
| else: | |
| raise | |
| except ZeroDivisionError: | |
| if ignore_zero_division: |
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
| def remidner(number, divisor): | |
| return number % divisor | |
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
| def normalize(numbers): | |
| total = sum(numbers) | |
| result = [] | |
| for value in numbers: | |
| percent = 100 * value / total | |
| result.append(percent) | |
| return result |
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
| >>> sum(range(11)) | |
| 55 | |
| >>> sum([i for i in range(1,11)]) | |
| 55 | |
| >>> sum(i for i in range(1,11)) | |
| 55 | |
| >>> import functools | |
| >>> from functools import reduce | |
| >>> reduce(lambda x,y: x + y, range(1,11)) | |
| 55 |
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
| def index_words(text): | |
| result = [] | |
| if text: | |
| result.append(0) | |
| for index, letter in enumerate(text): | |
| if letter == ' ': | |
| result.append(index + 1) | |
| return result | |
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
| def sort_priority(values, group): | |
| def helper(x): | |
| if x in group: | |
| return (0, x) | |
| return (1, x) | |
| values.sort(key=helper) |
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
| def divide(a, b): | |
| try: | |
| return a/b | |
| except ZeroDivisionError: | |
| return None | |
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
| BasicObject | |
| <- Kernel (module) | |
| <- PP::ObjectMixin(module) | |
| <- Object | |
| <- Person | |
| <- Customer |