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 Soma: | |
def soma(a, b, c=0): | |
return a+b+c |
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 Soma(){ | |
int soma(int a, int b){ | |
return a+b; | |
} | |
int soma(int a, int b, int c){ | |
return a+b+c; | |
} |
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 eh_diagonal_dominante(matriz): | |
... for i, linha in enumerate(matriz): | |
... soma = sum(linha) | |
... item_diagonal = linha[i] | |
... if item_diagonal <= (soma - item_diagonal): | |
... return False | |
... return True | |
... | |
>>> eh_diagonal_dominante([ | |
... [2, 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 Triangulo: | |
def __init__(self, a, b, c): | |
self.a = a | |
self.b = b | |
self.c = c | |
def gerar_lados_ordenados(self): | |
return sorted([self.a, self.b, self.c]) | |
def semelhantes(self, triangulo): |
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 itertools import groupby | |
from operator import itemgetter | |
def generate_batch(generator, batch_size=10): | |
if batch_size <= 1: | |
yield from generator | |
mod_generator = list((i // batch_size, v) for i, v in enumerate(generator)) | |
for mod, tpl in groupby(mod_generator, itemgetter(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 generate_batch(generator, batch_size=10): | |
batch = [] | |
for e in generator: | |
if len(batch) == batch_size: | |
yield batch | |
batch = [] | |
batch.append(e) | |
if batch: | |
yield batch |
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 collections import deque | |
from itertools import cycle | |
import pytest | |
REPLACEMENTS = ["CCTTGG", "CTATGG", "CCACGG"] | |
def replace_gen_sub_seq(seq, replacements): | |
seq = list(seq) |
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
-- Baseado na extensão ltree: https://www.postgresql.org/docs/current/static/ltree.html | |
-- Deve-se criar um banco | |
$ createdb mydb | |
$ psql mydb | |
-- Instalando extensão do ltree no banco | |
mydb=# CREATE EXTENSION ltree | |
-- Criando tabela com Categoria |
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 collections import Counter, OrderedDict | |
def all_perms_r(curr, freqs): | |
if all(value==0 for value in freqs.values()): | |
yield curr | |
for ch, freq in freqs.items(): | |
if freq == 0: | |
continue | |
freqs[ch] -= 1 | |
yield from all_perms_r(curr + ch, freqs) |
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 hacker_case(s): | |
dct = dict(zip('abc', '123')) | |
return map(dct.get, s, s) | |
if __name__ == '__main__': | |
print(''.join(hacker_case('abcdeuhsdfihusf6'))) |