Skip to content

Instantly share code, notes, and snippets.

@renzon
renzon / setexample
Created Mar 5, 2014
Utilizando set em Python
View setexample
palavra_chave = ['uva', 'limao', 'laranja', 'pera', 'maca', 'caju']
recurso = ['limao', 'pera' ]
palavra_set=set(palavra_chave)
recurso_set=set(recurso)
sobra=palavra_set-recurso_set
print sobra
@renzon
renzon / gist:9612518
Last active Aug 29, 2015
EstatiscaPythonBrasil
View gist:9612518
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
CADERNOS = [[13, 8, 19],
[3, 18, 4],
[14, 9, 20],
[14, 8, 10],
[1, 7, 2],
[3, 2, 10],
[10, 16, 7],
View fatorial
def fatorial(n):
def multiplicar(acumulador, elemento):
return acumulador * elemento
return reduce(multiplicar, xrange(1, n + 1))
@renzon
renzon / saque.py
Last active Aug 29, 2015
Código para geração de saques
View saque.py
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
QTD_INICIAL_DE_NOTAS = 10
NOTAS = [5, 10, 20, 50]
def sacar_recursiva(valor, saque, notas_disponiveis, qtdes_disponiveis):
# Se valor é 0, entao retorno é saque atual como resposta
View proximo_item.py
from itertools import izip
lista=range(5)
for elemento, proximo_elemento in izip(lista[:-1],lista[1:]):
print elemento,proximo_elemento
# Resultado
# 0 1
View exemplo_decorator.py
#decorator 1
from datetime import datetime
import functools
import logging
def query_checker(*keys_to_check):
""" Checks if a given key exists in the query string dictionary, if not, never executes the real handler and return status 400 """
def real_decorator(func):
@functools.wraps(func)
View cristiano.py
# Categoria
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from google.appengine.ext import ndb
class Categoria(ndb.Model):
descricao=ndb.StringProperty()
tipo=ndb.StringProperty()
View gist:5d63495c8dde2b09a74d
s = """{u'search_metadata': {u'count': 100, u'completed_in': 0.23599999999999999, u'max_id_str': u'407528290757668864', u'since_id_str': u'0', u'next_r
esults': u'?max_id=407528086326870015&q=%23PlateiaLuanSantana&count=100&include_entities=1', u'refresh_url': u'?since_id=407528290757668864&q=%2
3PlateiaLuanSantana&include_entities=1', u'since_id': 0, u'query': u'%23PlateiaLuanSantana', u'max_id': 407528290757668864}, u'statuses': [{u'co
ntributors': None, u'truncated': False, u'text': u'#PlateiaLuanSantana NUNCA FUI POR FAVOR ME SORTEIA @CFLuanSantana u', u'in_reply_to_status_id
': None, u'id': 407528290757668864, u'favorite_count': 0, u'source': u'<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for i
Phone</a>', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [{u'id': 177021046, u'indices': [51, 65],
u'id_str': u'177021046', u'screen_name': u'CFLuanSantana', u'name': u'Central de f\xe3s LS.'}], u'hashtags': [{u'indices': [0, 19], u'text': u'
Pla
@renzon
renzon / fcn.py
Last active Aug 29, 2015
Função como Parâmetro de outra
View fcn.py
def executador_de_funcao(fcn):
return fcn()
def a():
return 'A'
def b():
return 'B'
@renzon
renzon / input_lista.py
Created Apr 28, 2015
inputs em uma lsita
View input_lista.py
numeros = [int(input('Digite um numero: ')) for i in range(5)]
print(numeros)