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
# -*- coding: utf-8 -*- | |
class IMath: | |
"""Интерфейс для прокси и реального субъекта""" | |
def add(self, x, y): | |
raise NotImplementedError() | |
def sub(self, x, y): | |
raise NotImplementedError() | |
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 Stack: | |
def __init__(self): | |
self.stack = [] | |
def push(self, el): | |
self.stack.append(el) | |
def pop(self): | |
if len(self.stack) == 0: | |
raise StackEmptyError() |
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
""" | |
TODO | |
""" |
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
""" | |
TODO | |
""" |
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
set nocompatible | |
"Включаем распознавание типов файлов и типо-специфичные плагины: | |
filetype on | |
filetype plugin on | |
filetype plugin indent on | |
"Настройки табов для Python, согласно рекоммендациям | |
set tabstop=4 | |
set shiftwidth=4 |
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
# -*- coding: utf-8 -*- | |
# Целочисленне деление без оператора "деление" | |
def div(a,b): | |
if a < b: | |
return 0 | |
elif a == b: | |
return 1 |
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 Hash: | |
def __init__(self): | |
self.f = [] | |
self.s = [] | |
def add(self, key, value): | |
found = False | |
for i, val in enumerate(self.f): | |
if val == key: | |
self.s[i] == value |
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
import random | |
def rand5(): | |
seq = [0,1,2,3,4,5] | |
return random.choice(seq) | |
def rand7(): | |
i = 5 * (rand5() - 1) + rand5() | |
while i > 21: | |
i = 5 * (rand5() - 1) + rand5() |
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
#-*- coding: utf-8 -*- | |
class Girl: | |
methods = {'и':'у','й':'ю','ти':'щу','ей':'ью','ри':'рю', | |
'ери':'еру','ети':'ечу','ись':'усь','йся':'юсь', | |
'оди':'ожу','рай':'раю','вись':'вюсь','тись':'чусь'} | |
def __init__(self, name = 'Наташа'): | |
print 'Привет, меня зовут', name | |
self.name = name | |
def __del__(self): |
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
mylist = [x*x for x in range(3)] | |
for i in mylist : | |
print(i) | |
# Generators can be read only once | |
mygenerator = (x*x for x in range(3)) | |
for i in mygenerator : | |
print(i) | |
Yield is a keyword that is used like return, except the function will return a generator. |