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 pgzrun | |
from random import randint,choice | |
import string | |
letters = [] # will store letter,x,y | |
WIDTH = 800 | |
HEIGHT = 500 | |
velocity = 1 | |
colors = [0, 0, 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 random | |
import string | |
import sys | |
import pygame | |
# Initializing pygame | |
pygame.init() | |
# setting font | |
myfont = pygame.font.SysFont('monospace', 50) |
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 imaplib | |
import email | |
import os | |
def create_folder(folder_name="backup"): | |
""" | |
Creates a folder to store all mails | |
""" | |
if not os.path.exists(folder_name): |
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 bs4 import BeautifulSoup | |
from glob import glob | |
import os | |
import json | |
def get_folders(path=os.getcwd()): | |
""" | |
return a lst of all sub directories inside a folder | |
:param path: string |
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
corr = housing.corr() | |
# Using mask to get triangular correlation matrix | |
f, ax = plt.subplots(figsize=(15, 15)) | |
mask = np.zeros_like(corr, dtype=np.bool) | |
mask[np.triu_indices_from(mask)] = True | |
sns.heatmap(corr, mask=mask, cmap=sns.diverging_palette(220, 10, as_cmap=True), square=True, ax=ax, vmin = -1.0, vmax = 1.0, linewidths=.5) |
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
# Zaz Brown | |
# github.com/zaz/dijkstra | |
"""An efficient algorithm to find shortest paths between nodes in a graph.""" | |
from collections import defaultdict | |
class Digraph(object): | |
def __init__(self, nodes=[]): | |
self.nodes = set() | |
self.neighbours = defaultdict(set) | |
self.dist = {} |
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 requests | |
from bs4 import BeautifulSoup | |
def get_all_links(url): | |
content = requests.get(url).content | |
soup = BeautifulSoup(content, 'html.parser') | |
links = [] | |
for link in soup.find_all('a'): | |
if link.has_attr('href'): | |
href = link['href'] |
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 get_nth_fibo(n,cache): | |
if n in cache: | |
return cache[n] | |
else: | |
cache[n] = get_nth_fibo(n-1,cache) + get_nth_fibo(n-2,cache) | |
return cache[n] | |
print(get_nth_fibo(1,{1:0,2: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
def get_nth_fibo(n): | |
if n == 0: | |
return 0 | |
elif n ==2: | |
return 1 # the second number in the fibonacci series is always 1 | |
elif n == 1: | |
return 0 # the first number in the fibonacci series is always 1 | |
else: | |
return get_nth_fibo(n-1) + get_nth_fibo(n-2) | |
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
# Solution by Sai Ganesh | |
def singleNumber(nums): | |
dnum = {} | |
for i in nums: | |
if i in dnum.keys(): | |
dnum[i]+=1 | |
if i not in dnum.keys(): | |
dnum[i] = 1 | |
for k in dnum: | |
if dnum[k] == 1: |