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
| https://github.com/pypa/pip-test-package/archive/master.tar.gz#egg=pip-test-package |
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 sys | |
| from setuptools import setup | |
| deps = [] | |
| if sys.version_info >= (3,): | |
| deps.append('DEPENDENCY_A') | |
| else: | |
| deps.append('DEPENDENCY_B') |
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 Greeting(object): | |
| def __init__(self, msg): | |
| self.msg = msg | |
| def greet(self): | |
| return 'Hello %s!' % msg |
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 Person(object): | |
| def __init__(self, name): | |
| self.name = name | |
| people = [Person('hugo'), Person('igor')] | |
| for p in people: | |
| print p.name |
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 sys | |
| def tail_recursion_with_stack_inspection(g): | |
| ''' | |
| Version of tail_recursion decorator using stack-frame inspection. | |
| ''' | |
| loc_vars ={"in_loop":False,"cnt":0} | |
| def result(*args, **kwd): | |
| if not loc_vars["in_loop"]: |
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 fat(n): | |
| if n == 0: | |
| result = 1 | |
| else: | |
| result = n * fat(n - 1) | |
| return result | |
| """ | |
| fat(5) | |
| 5 * fat(4) |
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 timeit | |
| def memoize(fn): | |
| cache = {} | |
| def newfn(arg): | |
| if arg in cache: | |
| return cache[arg] | |
| else: | |
| cache[arg] = fn(arg) |
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 pprint | |
| pessoas = [ | |
| {'nome': 'Adolfo', 'estado': 'MG'}, | |
| {'nome': 'Igor', 'estado': 'CE'}, | |
| {'nome': 'Pedro', 'estado': 'RS'}, | |
| {'nome': 'Maria', 'estado': 'AC'}, | |
| ] | |
| def por_nome(pessoa1, pessoa2): |
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 encode(text): | |
| if not text: | |
| return "" | |
| else: | |
| last_char = text[0] | |
| max_index = len(text) | |
| i = 1 | |
| while i < max_index and last_char == text[i]: | |
| i += 1 | |
| return last_char + str(i) + encode(text[i:]) |
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
| # using tail recursion | |
| def merge(l, r, acc): | |
| if not l: | |
| return acc + r | |
| elif not r: | |
| return acc + l | |
| if l[0] < r[0]: | |
| return merge(l[1:], r, acc + [l[0]]) | |
| else: |