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 unicodedata import name | |
>>> name('ˆ') | |
'MODIFIER LETTER CIRCUMFLEX ACCENT' | |
>>> name('^') | |
'CIRCUMFLEX ACCENT' | |
>>> |
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 django.urls import reverse | |
def test_reverse(): | |
assert '/inscricao/' == reverse('subscriptions:new') |
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 django.conf.urls import url | |
from eventex.subscriptions.views import new, detail | |
urlpatterns = [ | |
url(r'ˆ$', new, name='new'), | |
url(r'ˆ(\d+)/$', detail, name='detail'), | |
] |
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 django.conf.urls import url, include | |
from django.contrib import admin | |
from eventex.core.views import home | |
urlpatterns = [ | |
url(r'^$', home, name='home'), | |
url(r'^inscricao/', | |
include('eventex.subscriptions.urls', namespace='subscriptions')), | |
url(r'^admin/', admin.site.urls), |
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 truncar(texto:str, largura:'int > 0'=80) -> str: | |
'''devolve o texto truncado no primeiro espaço até a largura, | |
ou no primeiro espaço após a largura, se existir | |
''' | |
termino = None | |
if len(texto) > largura: | |
pos_espaco_antes = texto.rfind(' ', 0, largura) | |
if pos_espaco_antes >= 0: | |
termino = pos_espaco_antes | |
else: |
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 _Opcao: | |
def retorno_da_aposta(self): | |
raise not NotImplementedError() | |
class _Casa(_Opcao): | |
def retorno_da_aposta(self): | |
"""Estrategia de aposta em casa""" | |
return 'Casa' |
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 Arvore: | |
def __init__(self, valor, *filhos): | |
"""Inicializador de árvore | |
:param valor: object valor que o nó possui | |
:param filhos: list de filhos desse nó | |
""" | |
self.valor = valor | |
self.filhos = filhos |
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 time_lapse(total_seconds): | |
minute_to_seconds = 60 | |
hour_to_seconds = minute_to_seconds * 60 | |
day_to_seconds = hour_to_seconds * 24 | |
days, remaining_seconds = divmod(total_seconds, day_to_seconds) | |
hours, remaining_seconds = divmod(remaining_seconds, hour_to_seconds) | |
minutes, remaining_seconds = divmod(remaining_seconds, minute_to_seconds) | |
return days, hours, minutes, remaining_seconds |
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 unique_list(lst): | |
backtrack = set() | |
def hash_dicts(dct): | |
if isinstance(dct, dict): | |
return str(sorted((k, hash_dicts(v)) for k, v in dct.items())) | |
return str(dct) | |
def is_repeated(dct): | |
hashable = hash_dicts(dct) |
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
N = 2 | |
lst = [0] * N | |
try: # Mantenha no try só o que pode dar pau | |
for i in range(N): | |
lst[i] = float(input('%sº número: ' % (i + 1))) | |
except(ValueError, TypeError): | |
print('Valor inválido') | |
else: # Aqui vai o código se não houve erro | |
print('primeiro elemento:', lst[0]) | |
print('A soma dos numeros %s é %f' % ('; '.join(map(str, lst)), sum(lst))) |