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 merge(p, q, r, v): | |
w = [] | |
i, j = p, q | |
while i < q and j < r: | |
if v[i] <= v[j]: | |
w.append(v[i]) | |
i += 1 | |
else: | |
w.append(v[j]) | |
j += 1 |
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
from heapq import heappush, heappop | |
def heapsort(v): | |
h = [] | |
for x in v: | |
heappush(h, x) | |
return [heappop(h) for i in range(len(h))] | |
from random import shuffle | |
v = list(range(8)) | |
shuffle(v) |
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
#versão Python 3 de http://pastebin.com/uRnDZaTz (Vinicius Marangoni) | |
import urllib.request | |
import json | |
url = 'http://divulga.tse.jus.br/2014/divulgacao/oficial/143/dadosdivweb/br/br-0001-e001431-w.js' | |
def main(): | |
resp = urllib.request.urlopen(url).read() | |
resp = json.loads(resp.decode('utf-8')) | |
candidatos = resp['cand'] |
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
#traduzido e adaptado de http://blog.trinket.io/writing-poetry-in-python/ | |
from random import choice, randint | |
adjetivos = '''compreensivo temperamental confiável confiável honesto desonesto | |
interessante chato carinhoso simpático amigável generoso ciumento invejoso | |
inseguro ambicioso ansioso bondoso sensato sensível teimoso preguiçoso | |
trabalhador calmo paciente inteligente esperto espirituoso astuto neurótico | |
ousado apático cínico sarcástico irônico cético alegre conservador pessimista | |
otimista tolerante corajoso educado mal-educado determinado sociável | |
solidário arrogante maldoso desajeitado burro independente confiável dependente |
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
# BlueBook code decryption | |
import sys | |
def sieve(n): | |
# Compute primes using sieve of Eratosthenes | |
x = [1] * n | |
x[1] = 0 | |
for i in range(2,n//2): | |
j = 2 * i | |
while j < n: | |
x[j] = 0 |
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 urllib.request | |
import json | |
url = 'http://educacao.dadosabertosbr.com/api/escolas?nome=' | |
escola = 'embraer' | |
resp = urllib.request.urlopen(url+escola).read() | |
resp = json.loads(resp.decode('utf-8')) | |
for x in resp[1]: | |
print (x['nome']) | |
print ('Código:', x['cod']) | |
print (x['cidade'], x['estado']) |
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 urllib.request | |
import json | |
url = 'http://educacao.dadosabertosbr.com/api/escola/' | |
codigo = '35141240' | |
resp = urllib.request.urlopen(url+codigo).read() | |
resp = json.loads(resp.decode('utf-8')) | |
print (resp['nome']) | |
print ('Salas:', resp['salasExistentes']) | |
print ('Computadores:', resp['computadores']+resp['computadoresAdm']+resp['computadoresAlunos']) | |
print ('Formação Docente:', resp['formacaoDocente']) |
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 urllib.request | |
import json | |
url = 'http://educacao.dadosabertosbr.com/api/escolas/buscaavancada?situacaoFuncionamento=1&energiaInexistente=on&aguaInexistente=on&esgotoInexistente=on' | |
resp = urllib.request.urlopen(url).read() | |
resp = json.loads(resp.decode('utf-8')) | |
print ('Número de Escolas em funcionamento sem energia, água e esgoto:', resp[0]) | |
for x in resp[1]: | |
print (x['nome'], x['cod']) | |
print (x['cidade'], x['estado'], x['regiao']) | |
print () |
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
#The context of this program is a course of an hour to journalists who know nothing about programming in a lab with Python 3 only. | |
import urllib.request | |
import json | |
def analisa_detalhe(cod): | |
url = 'http://educacao.dadosabertosbr.com/api/escola/' | |
resp = urllib.request.urlopen(url+str(cod)).read() | |
resp = json.loads(resp.decode('utf-8')) | |
if int(resp['salasExistentes']) > 1: | |
print ('Salas Existentes:', resp['salasExistentes']) |
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
#The context of this program is a course of an hour to journalists who know nothing about programming in a lab with Python 3 only. | |
import urllib.request | |
url = 'http://www.portaltransparencia.gov.br/copa2014/api/rest/empreendimento' | |
resp = urllib.request.urlopen(url).read().decode('utf-8') | |
total = 0 | |
j = 0 | |
and1 = '<andamento>' | |
and2 = '</andamento>' | |
abre = '<valorTotalPrevisto>' | |
fecha = '</valorTotalPrevisto>' |