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
g = {} | |
g[1] = [2, 3, 5] | |
g[2] = [1, 6, 4] | |
g[3] = [1, 4, 7] | |
g[4] = [2, 3, 8] | |
g[5] = [1, 6, 7] | |
g[6] = [2, 5, 8] | |
g[7] = [3, 5, 8] | |
g[8] = [4, 6, 7] | |
removidos = [True] + 8 * [False] |
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
#@gwidion code | |
print"".join(u"\x1b[%dm%c%s"%((42+y%2^y>>3&1),((1,3,2,-1,0,2,3,1)+(4,)*8+32*(-9781,)+8*(10,)+(7,9,8,5,6,8,9,7))[y]+9813,(y+1)%8and" "or" \x1b[48m\n")for y in range(64)) |
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 merge(e, d): | |
r = [] | |
i, j = 0, 0 | |
while i < len(e) and j < len(d): | |
if e[i] <= d[j]: | |
r.append(e[i]) | |
i += 1 | |
else: | |
r.append(d[j]) | |
j += 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
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 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>' |
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
#Pi Generator ref https://mail.python.org/pipermail/edu-sig/2015-September/011317.html | |
def pi_digits(): | |
k, a, b, a1, b1 = 2, 4, 1, 12, 4 | |
while True: | |
p, q, k = k*k, 2*k+1, k+1 | |
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 | |
d, d1 = a//b, a1//b1 | |
while d == d1: | |
yield int(d) | |
a, a1 = 10*(a%b), 10*(a1%b1) |
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
# | |
# API DEPRECATED AT JUNE 2013 | |
# https://dev.twitter.com/docs/faq#17750 | |
# | |
import urllib, json | |
def busca_tweets(texto='python'): | |
url = 'http://search.twitter.com/search.json?q=' + texto | |
resp = urllib.urlopen(url).read() | |
data = json.loads(resp) |
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
# | |
# API DEPRECATED AT JUNE 2013 | |
# https://dev.twitter.com/docs/faq#17750 | |
# | |
import urllib, json | |
def trend_topics(): | |
url = 'https://api.twitter.com/1/trends/1.json' | |
resp = urllib.urlopen(url).read() |
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
import urllib | |
import json | |
url = 'https://graph.facebook.com/19292868552' | |
resp = urllib.urlopen(url).read() | |
data = json.loads(resp) | |
url_logo = data['cover']['source'] | |
imagem = urllib.urlopen(url_logo).read() |
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
import urllib | |
import json | |
def grava_imagem(amigo): | |
url = 'https://graph.facebook.com/' + amigo['id'] + '/picture?type=large' | |
figura = urllib.urlopen(url).read() | |
f = open (amigo['name'] + '.jpg', 'wb') | |
f.write (figura) | |
f.close() |
OlderNewer