blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string |
|---|---|---|---|---|---|---|
516b366e5254a898ed885eab1d7311dd3fb6e7f2 | Hwannnn/Project_Euler | /projectEuler/ex20.py | 285 | 3.65625 | 4 | from math import factorial
def ah_hagisilda(n) :
sum = 0
str_num = str(fac_num)
for i in range(0,len(str_num)) :
sum += int(str_num[i])
print sum
#########################################
number = 100
fac_num = factorial(number)
ah_hagisilda(fac_num)
|
bc5dc611d9106f607afc22ad349f9fcae60577b0 | Hwannnn/Project_Euler | /projectEuler/ex16.py | 186 | 3.546875 | 4 |
def add(n) :
str_n = str(n)
sum = 0
for i in range(0,len(str_n)) :
sum+=int(str_n[i])
print sum
###########################################
x = 2**1000
add(x)
|
9671dff9c5e765f83307822eca3103a5dae43ede | dsar/mobility_pattern_detection | /code/local/utils_mobility.py | 17,581 | 3.515625 | 4 | from libraries import *
def fill_gps_coordinates(row):
"""
Feels any missing GPS information from the location information provided in the placeLongitude and placeLatitude
columns
Parameters
----------
row: dataframe row
Returns
-------
row feeled with missing data
""... |
809873868aeec6ee19002ff3080a646ea122549c | arrancapr/Clases | /Python1ArrancaPr/Samples/ClassesDemo2.py | 970 | 3.96875 | 4 | #Created by alfredo alvarez
# demo of a class basic principlpes
class PrintingProxy:
def myprint(self, s):
print(s)
class PrinterForTest:
def __init__(self):
self.text = ""
def myprint(self, s):
self.text = s
#example class
class ExampleClass:
#standard definition of... |
8c227306e514f62afb87d69ad096a71dc479db24 | arrancapr/Clases | /Python1ArrancaPr/Samples/FunctionDemo.py | 1,033 | 4.125 | 4 | #Example comment code written in python 3.3.0
#by Alfredo Alvarez
#Basic function demonstrates passing a parameter with no return value
def firstFunction(throwError):
if throwError:
raise ValueError("showing the error functionality")
else:
print("function works yeah")
print("only run if err... |
04aca29e06602d4a6c2bfecfebbe4f5668f5270e | S1mp41w3/Umuzi_Data_Engineering_Pre-Bootcamp_Excerceises | /task-2-dataEngineering-preBootCamp.py | 593 | 3.734375 | 4 | # -*- coding: utf-8 -*-
"""
Umuzi Data Engineering Pre-Bootcamp
@author: Simphiwe Shongwe
@Git: S1mp41w3
@E-mail: Sim01Shongwe@gmail.com
Task 2
Convert this pseudocode into actual code. Make it run.
Make sure you understand the results.
This is a fundamental lesson.
If you donโt understand the result... |
bfde15e97bb861520dfd1856c5f48aaaf2890da0 | NamraAnsari/SQLiteToExcel | /StudentDatabase.py | 359 | 3.640625 | 4 | import sqlite3
class StudentData:
@staticmethod
def create_tables():
conn = sqlite3.connect('record.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE STUDENT(S_ID INTEGER PRIMARY KEY AUTOINCREMENT, S_NAME VARCHAR(50) NOT NULL,"
" S_POSITION VARCHAR(50) NO... |
4697422dde38b102118b2bddcbdf38f09d8f08f6 | MysticVagabond/PythonDev | /Project Files/Encrypter_V2/EncryptScoreAndName.py | 1,864 | 3.6875 | 4 | import random
def createName(name, key):
newName = ''
for letter in name:
num = ord(letter)
num += key
if letter.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26
elif letter.islower():
if n... |
ac7f9856aef70b6d3fa98e86107be1ada83533e1 | sillyer/learn-python-the-hard-way | /ex32.py | 426 | 4.0625 | 4 | numbers = [1,2,3,4,5]
fruits = ['apple','orange','banana','strawburry','lemon']
change = ['apple',1,'orange',2,'banana',4]
for count in numbers:
print "the number is %d" % count
for fruit in fruits:
print "the fruit is %s" % fruit
for i in change:
print "the output is %r" % i
element = []
for a in range(0,6):
... |
856bfbc72a87f59eafe4122646cd996fa171b7db | tovakarp/Python-Iterators-Generators | /Iterators/my_accumulate.py | 169 | 3.890625 | 4 | def my_accumulate(iterable):
count = 0
for elem in iterable:
count += elem
yield count
for elem in my_accumulate([1,2,3,4,5]):
print(elem) |
612aa398a89a43d16a859a9e666955bee9c6ea7c | birsandiana99/UBB-Work | /GRAPHS/Practical work no 3/Domain.py | 9,206 | 3.671875 | 4 | class Graph:
def __init__(self, n):
self.__listIn = [[] for i in range(n)] #lista de liste self._listIn = []
self.__listOut = [[] for i in range(n)]
self.__size = n
for i in range(0,n):
#print(i)
self.__listIn[i] = []
self.__listOut[i] = [... |
8feded663096270c4a466cce7ea3723718431258 | birsandiana99/UBB-Work | /FP/Problems/minesweeper.py | 3,921 | 3.5625 | 4 | from texttable import Texttable
from random import choice
class Board:
def __init__(self, size, mines):
self._size = size
self._mines = mines
self._data = []
self._revelead = []
for i in range(self.size):
self._data.append([' '] * self.size)
s... |
7786b8f401d7502f4d8862cc6d3404a48fb26f1f | birsandiana99/UBB-Work | /GRAPHS/Practical work no 1/main.py | 3,570 | 3.578125 | 4 | from UI import UI
from Domain import Graph
from Iterator import verticesIterator
def readFile(fileName):
with open(fileName, 'r') as f:
line = f.readline().split()
print(line)
n = int(line[0]) # vertices
#m = int(line[1]) # edges
graph = Graph(n)
... |
e9b5abce3cdf7de669982099cd7501e05993db48 | birsandiana99/UBB-Work | /GRAPHS/Practical work no 2/roottree.py | 1,362 | 3.796875 | 4 | class RootedTree:
def __init__(self, root):
self.__root = root
self.__children = {root:[]}
self.__parent = {root:None}
def add_child(self, vertex, new_vertex):
#adds new_vertex as child of vertex
#precondition: vertex exists, new_vertex does not
self.__ch... |
eb22831ac019a65139237ab475f079bd5c336c09 | llb1008x/API | /study/daily_code/python/day_7/test.py | 391 | 3.765625 | 4 | #!/usr/bin/env python
# coding=utf-8
from itertools import islice
class Fib:
def __init__(self):
self.prev = 0
self.curr = 1
def __iter__(self):
return self
def __next__(self):
value = self.curr
self.curr += self.prev
self.prev = value
... |
8a06880cedd8258610eda993c08b0c68a01ab111 | llb1008x/API | /study/4.python/api/function/recu.py | 861 | 4.25 | 4 | #!/usr/bin/env python
# coding=utf-8
#ๅพช็ฏ
'''
def factorial(n):
result = n;
for i in range(1,n):
result *= i
return result
num = input("please input:")
print(factorial(int(num)))
'''
#้ๅฝ็
'''
def factorial(n):
if n == 1:
return 1
else :
return factorial(n-1)*n
... |
04349f2feb05e86c0ab7b5f5d7677a338134c5c0 | llb1008x/API | /study/daily_code/C_and_C++/day_104/python_test.py | 255 | 3.53125 | 4 | #!/usr/bin/env python
# coding=utf-8
import numpy as np
import matplotlib.pyplot as plt
plt.figure(1)
ax=plt.subplot(111)
x=np.linspace(0,np.pi*2,200)
r=2*np.cos(x)
ax.plot(r*np.cos(x),r*np.sin(x))
r=1
ax.plot(r*np.cos(x),r*np.sin(x))
plt.show()
|
08583d0ec828a02a03b333d2d8064d594eb62245 | llb1008x/API | /study/4.python/api/net/3.ไฟๅญ็ฝ็ปๅพ็.py | 722 | 3.703125 | 4 | #!/usr/bin/env python
# coding=utf-8
#็ฌ่ซ็ฝ็ปๅพ็
import requests
import os
url="http://image.nationalgeographic.com.cn/2017/0211/20170211061910157.jpg"
root='/home/llb/project/API/study/python/daily_code/day_16/'
path=root+url.split('/')[-1]
def getHTMLText(url):
try:
if not os.path.exists(root):
... |
6befdd0bb431b29e0da25987be3c3dc50a17bd39 | YukiyaWada/deep-learning-from-scratch | /ch02/perceptron.py | 693 | 3.515625 | 4 | import numpy as np
# two-input perceptron.
# x is an array of 2 in length.
# w is weight(an array of 2 in length), b is bias(integer).
def perceptron2(x, w, b):
if b + np.sum(x * w) <= 0:
return 0
else:
return 1
def AND2(x):
w, b = np.array([1, 1]), -1.5
return perceptron2(x, w, b)
de... |
a03fd819553586fe40524bfc8c29f67576196f19 | y281473724/Py-base | /collectionsๅบ.py | 4,412 | 4.25 | 4 | #collectionsๆฏPythonๅ
ๅปบ็ไธไธช้ๅๆจกๅ๏ผๆไพไบ่ฎธๅคๆ็จ็้ๅ็ฑปใ
#namedtuple
from collections import namedtuple
Point = namedtuple('tuple',['x','y'])
p = Point(1,2)
print(p.x,p.y)
"""
namedtupleๆฏไธไธชๅฝๆฐ๏ผๅฎ็จๆฅๅๅปบไธไธช่ชๅฎไน็tupleๅฏน่ฑก๏ผ
ๅนถไธ่งๅฎไบtupleๅ
็ด ็ไธชๆฐ๏ผ
ๅนถๅฏไปฅ็จๅฑๆง่ไธๆฏ็ดขๅผๆฅๅผ็จtuple็ๆไธชๅ
็ด ใ
่ฟๆ ทไธๆฅ๏ผๆไปฌ็จnamedtupleๅฏไปฅๅพๆนไพฟๅฐๅฎไนไธ็งๆฐๆฎ็ฑปๅ๏ผ
ๅฎๅ
ทๅคtuple็ไธๅๆง๏ผๅๅฏไปฅๆ นๆฎๅฑๆงๆฅๅผ็จ๏ผไฝฟ็จๅๅๆน... |
12daef91d4c06e36de81d3b11f974f58ee494bd1 | y281473724/Py-base | /map()ๅฝๆฐไฝฟ็จๆนๆณ.py | 356 | 4.0625 | 4 | """
map()ๅฝๆฐๆฅๆถไธคไธชๅๆฐ๏ผไธไธชๆฏๅฝๆฐ๏ผ
ไธไธชๆฏIterable๏ผmapๅฐไผ ๅ
ฅ็ๅฝๆฐ
ไพๆฌกไฝ็จๅฐๅบๅ็ๆฏไธชๅ
็ด ๏ผๅนถๆ็ปๆ
ไฝไธบๆฐ็Iterator่ฟๅใ
"""
#ๆนๆณไธ
def f(x):
return x*x
r = map(f,[1, 2, 3, 4, 5, 6, 7, 8, 9])
print(list(r))
#ๆนๆณไบ
l = list(map(str,[1, 2, 3, 4, 5, 6, 7, 8, 9]))
print(l)
|
5cbc0f1aa6ec12a36a407e0f5c011c58a81230fd | y281473724/Py-base | /sorted()ๅฝๆฐไฝฟ็จๆนๆณ.py | 801 | 4.28125 | 4 | """
Pythonๅ
็ฝฎ็sorted()ๅฝๆฐๅฏไปฅๅฏนlist่ฟ่กๆๅบ(้ป่ฎคไปๅฐๅฐๅคง)
ๆญคๅค๏ผsorted()ๅฝๆฐไนๆฏไธไธช้ซ้ถๅฝๆฐ๏ผๅฎ่ฟๅฏไปฅๆฅๆถไธไธชkeyๅฝๆฐๆฅๅฎ็ฐ่ชๅฎไน็ๆๅบ
"""
#ไพ1๏ผ
lt = sorted([36, 5, -12, 9, -21])
print(lt)
#ไพ2๏ผ
lt = sorted([36, 5, -12, 9, -21], key=abs)
print(lt)
#ไพ3๏ผ
#้ป่ฎคๆ
ๅตไธ๏ผๅฏนๅญ็ฌฆไธฒๆๅบ๏ผๆฏๆ็
งASCII็ๅคงๅฐๆฏ่พ็๏ผ
#็ฑไบ'Z' < 'a'๏ผ็ปๆ๏ผๅคงๅๅญๆฏZไผๆๅจๅฐๅๅญๆฏa็ๅ้ข
#ๅญ็ฌฆไธฒๅคงๅฐๆฏ่พๆนๆณ๏ผไป็ฌฌไธไธชๅญ็ฌฆๅผๅง๏ผไฝ็ฝฎไธไธๅฏนๅบๆฏ่พ็ผ็ ๅคงๅฐ๏ผๆๅๆฏ... |
570a3112dbe40b3e8261ce3c717fc99af0df7ee3 | Slavin22/PythonChallenge | /PyBank/main.py | 1,802 | 3.984375 | 4 | # Import Dependencies + load file-path
import os
import csv
csvpath = os.path.join('Resources', 'budget_data_1.csv')
# Establish variables + arrays
months = 0
total = 0
revenues = []
changes = 0
comp = 0
increase = 0
decrease = 0
incmonth = ""
decmonth = ""
# Read in CSV file
with open(csvpath, newline = "") as csvfi... |
ccd439b48220d1a9c99ba8a1c9e241bb0cc8cd5b | gf712/Stats | /Cluster_metrics/pFS.py | 1,292 | 3.5 | 4 | # Author: Gil Ferreira Hoben
import numpy as np
def pfs_(labels,X, cluster_centre=None):
"""
Calculate pFS value for a given clustering results
------
Input:
labels:
numpy array with cluster labels
X:
numpy array (shape = (data point count,
dimensions)
data points used in the clustering
cluster_... |
70f254be9b0d993aa543cbde73781969475ffeb0 | johnpcooke94/project-scrumger-games | /src/Sprites/frog_nest.py | 2,291 | 3.609375 | 4 | import pygame.sprite
from Util.asset_dictionary import AssetDictionary
class FrogNest(pygame.sprite.Sprite):
"""
Pygame sprite class for frog nests used for checking the win condition.
"""
# Constructor should be passed an int to indicate which nest position the sprite should go in
def __init__(s... |
abca1d6cba920db9413789cd9f098b5e60152ef1 | johnpcooke94/project-scrumger-games | /src/Sprites/turtle_animated.py | 5,075 | 4.25 | 4 | import pygame.sprite
from Sprites.turtle import Turtle
class TurtleSinker(Turtle):
"""Pygame sprite class representing an animated turtle"""
def __init__(self, frames, frame_spawned_on, x, y, animation_speed=18):
"""
- :param frames:
A list of images which will be cycled through ... |
cbd4aa5ccda77dd1e5cd70a892a6fa3948cfad56 | johnpcooke94/project-scrumger-games | /src/Sprites/player.py | 15,447 | 3.5 | 4 | import pygame.sprite
import pygame.surface
from Util.window import Window
from Util.asset_dictionary import AssetDictionary
class Player(pygame.sprite.Sprite):
"""
Pygame sprite class representing the player. Constructor should be passed a pygame LayeredUpdates object to
which the Player object will be ad... |
3fad365ab9b40e43dc9f519f6b096850f39ba66c | itluobo/pytoy | /func.py | 2,105 | 3.953125 | 4 | #!/usr/bin/python
# -*- coding: UTF-8 -*-
# ๅฝๆฐไปฃ็ ๅไปฅ def ๅ
ณ้ฎ่ฏๅผๅคด๏ผๅๆฅๅฝๆฐๆ ่ฏ็ฌฆๅ็งฐๅๅๆฌๅท()ใ
# ไปปไฝไผ ๅ
ฅๅๆฐๅ่ชๅ้ๅฟ
้กปๆพๅจๅๆฌๅทไธญ้ดใๅๆฌๅทไน้ดๅฏไปฅ็จไบๅฎไนๅๆฐใ
# ๅฝๆฐ็็ฌฌไธ่ก่ฏญๅฅๅฏไปฅ้ๆฉๆงๅฐไฝฟ็จๆๆกฃๅญ็ฌฆไธฒโ็จไบๅญๆพๅฝๆฐ่ฏดๆใ
# ๅฝๆฐๅ
ๅฎนไปฅๅๅท่ตทๅง๏ผๅนถไธ็ผฉ่ฟใ
# return [่กจ่พพๅผ] ็ปๆๅฝๆฐ๏ผ้ๆฉๆงๅฐ่ฟๅไธไธชๅผ็ป่ฐ็จๆนใไธๅธฆ่กจ่พพๅผ็return็ธๅฝไบ่ฟๅ Noneใ
# python ๅฝๆฐ็ๅๆฐไผ ้๏ผ
# ไธๅฏๅ็ฑปๅ๏ผ็ฑปไผผ c++ ็ๅผไผ ้๏ผๅฆ ๆดๆฐใๅญ็ฌฆไธฒใๅ
็ปใๅฆfun๏ผa๏ผ๏ผไผ ้็ๅชๆฏa็ๅผ๏ผๆฒกๆๅฝฑๅaๅฏน่ฑกๆฌ่บซใๆฏๅฆๅจ fun๏ผa๏ผๅ
้จไฟฎๆน a... |
d80c6c21de69524be73d5720a3e8c62381017ce9 | Szymchack/CIT228 | /Chapter6/rivers.py | 510 | 4.09375 | 4 | rivers={
'Indus':'Tibet, Kashmir, and Pakistan',
'Rhine':'Switzerland, Germany, and The Netherlands',
'Volga':'Russia'
}
for river, country in rivers.items():
print("The " + river.title() + " river flows through " + country.title() + ".")
print("\n The items in the key list for rivers are:")
f... |
fb8aab3ee439725d2b5c97e9a5b9e667e444fd76 | Szymchack/CIT228 | /Chapter7/seating.py | 216 | 4 | 4 | party=input("How many people are there in your party, please?")
party=int(party)
if party > 8:
print(f"\n I am sorry, you will have to wait until a table is ready")
else:
print(f"\nYour table is ready!") |
9f2a605c6e6fbfeadc13c5a5bdd1e7407a96f0d6 | Szymchack/CIT228 | /Chapter11/city_functions.py | 575 | 3.828125 | 4 | print("---------------11-1---------------")
def city_country(city, country):
return f"{city.title()}, {country.title()}"
print("---------------11-2---------------")
def city_country(city, country, population):
output_string = f"{city.title()}, {country.title()}"
output_string += f" -popul... |
376a5b97142e7b42626cd70ec8a987d5ae0d3116 | Szymchack/CIT228 | /Chapter9/user_class.py | 1,608 | 3.53125 | 4 | class User():
def __init__ (self, first_name, last_name, email, username, location, password):
self.first_name = first_name.title()
self.last_name = last_name.title()
self.email = email.title()
self.username = username.title()
self.location = location.title()
s... |
acdda4a35e7a1903e84fb20241360e788f1b69bd | simozawit/100DCC | /Day10challenge.py | 532 | 3.796875 | 4 | def Average(L):
try:
moy= sum(L)/len(L)
except ZeroDivisionError as error:
print (" The list is empty")
else:
return moy
students = [
{ "name": "Jose", "marks": [56, 77, 97] },
{ "name": "Rolf", "marks": [45, 80] },
{ "name": "Anna", "marks": [87, 75, 100, 95, 98] },
{ "name"... |
fb4960bc87663664fda19e4d4c7e242fa286c179 | theabhishekmandal/MachineLearning | /Machine Learning A-Z New/Part 1 - Data Preprocessing/Main.py | 2,162 | 4.0625 | 4 | import numpy as np
import pandas as pd
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
import matplotlib.pyplot as plt
from sklearn.compose import ColumnTransformer
from sklearn.model_selection import train_test_split
import warnings
# ignoring the future warnings... |
78f86e1f94596f60f170b062fa72a8eb5c01718c | jaapdejong/cryptopals | /set2/11-An-ECB-CBC-detection-oracle | 3,428 | 3.515625 | 4 | #!/usr/bin/python
# An ECB/CBC detection oracle
# Now that you have ECB and CBC working:
#
# Write a function to generate a random AES key; that's just 16 random bytes.
#
# Write a function that encrypts data under an unknown key --- that is, a function that generates a random key and encrypts under it.
#
# The fun... |
2b325ebe7edde403ae59e2d15265933f861a566f | burgerdev/turbo-dangerzone | /test_class_code.py | 221 | 3.734375 | 4 | #!/usr/bin/python2
d = dict()
print(d)
class MyClass(object):
d['a'] = 1
print(d)
def someMethod(self):
pass
if __name__ == "__main__":
print(d)
d['a'] = 2
m = MyClass()
print(d)
|
eab040788f99dc8c974cfb9387006510bbb38476 | chanyoonzhu/leetcode-python | /085-Maximal_Rectangle.py | 1,770 | 3.578125 | 4 | """
- dynamic programming
- challenge: each '1' can be corner of multiple rectangles, any of them can be the largest (unlike problem 221 with only squares)
- O(m^2*n), O(mn)
"""
class Solution:
def maximalRectangle(self, matrix: List[List[str]]) -> int:
M, N = len(matrix), len(matrix[0])
dp... |
a9bcadfacf8483b4b934ea69aec72619c0bae606 | chanyoonzhu/leetcode-python | /416-Partition_Equal_Subset_Sum.py | 2,006 | 3.59375 | 4 | """
- dynamic programming (top-down)
- O(n*s), O(n*s) - s is the sum
"""
class Solution:
def canPartition(self, nums: List[int]) -> bool:
div, mod = divmod(sum(nums), 2)
if mod: return False
@lru_cache
def dp(i, total):
if i >= len(nums):
return T... |
c473ee4502c3ff2761f7c1da154675023b243cac | chanyoonzhu/leetcode-python | /399-Evaluate_Division.py | 2,326 | 3.59375 | 4 | """
- graph bfs search
- O(n*E), O(E) n - number of queries E - number of equations
"""
class Solution:
def calcEquation(self, equations: List[List[str]], values: List[float], queries: List[List[str]]) -> List[float]:
graph = collections.defaultdict(dict)
for i in range(len(equations)):
... |
e955303f77cb1733595b2b3d417107baf2d1f51b | chanyoonzhu/leetcode-python | /796-Rotate_String.py | 1,042 | 3.640625 | 4 | """
- brute force
- O(n^2), O(n)
"""
class Solution:
def rotateString(self, s: str, goal: str) -> bool:
n = len(s)
if n != len(goal): return False
for i in range(n):
if s[i:] + s[:i] == goal:
return True
return False
"""
- rolling hash
- O(n), O(... |
826fed278f4b4651f672cfa495e186cdb9aeb3b7 | chanyoonzhu/leetcode-python | /279-Perfect_Squares.py | 2,776 | 3.703125 | 4 | """
- dynamic programming (top-down)
- O(n * sqrt(n)), O(n)
- TLE
"""
class Solution:
def numSquares(self, n: int) -> int:
dp = [float("inf")] * (n + 1)
dp[0] = 0
def dfs(n):
if dp[n] == float("inf"):
a = 1
while a ** 2 <= n:
... |
47e4238dc86a2d1725376847683a932604bdc78f | chanyoonzhu/leetcode-python | /2049-Count_Nodes_With_the_Highest_Score.py | 1,095 | 3.53125 | 4 | """
- tree (dfs)
- O(n), O(n)
"""
class Solution:
def countHighestScoreNodes(self, parents: List[int]) -> int:
# can have at most three parts: left subtree, right subtree, others
N = len(parents)
score_counts = defaultdict(int)
children_map = defaultdict(list)
... |
01bca0dfaec6ca69d663b63030c15c818e04e3d7 | chanyoonzhu/leetcode-python | /157-Read_N_Characters_Given_Read4.py | 1,719 | 3.828125 | 4 | """
The read4 API is already defined for you.
@param buf4, a list of characters
@return an integer
def read4(buf4):
# Below is an example of how the read4 API can be called.
file = File("abcdefghijk") # File is "abcdefghijk", initially file pointer (fp) points to 'a'
buf4 = [' '] * 4 # Create buffer with ... |
8228c1a675aaf80816c8028d6016b77dcf7d3efc | chanyoonzhu/leetcode-python | /karat/Karat-Invalid_Badge_Records.py | 1,497 | 3.515625 | 4 | """
badge_records = [
["Martha", "exit"],
["Paul", "enter"],
["Martha", "enter"],
["Martha", "exit"],
["Jennifer", "enter"],
["Paul", "enter"],
["Curtis", "enter"],
["Paul", "exit"],
["Martha", "enter"],
["Martha", "exit"],
["Jennifer", "exit"],
]
Expected ou... |
851ca382e3aaed65c6b0b11a83375b2fe82c9eee | chanyoonzhu/leetcode-python | /251-Flatten_2D_Vector.py | 1,085 | 3.5625 | 4 | """
- with index pointers
- key: 1. row can have [] array, need to continuously go to next row to find next 2. next and hasNext can to be called independently, must find current valid in both methods
"""
class Vector2D:
"""
- O(1)
"""
def __init__(self, vec: List[List[int]]):
self.vec = vec
... |
739478cce8cd0e9ce69df8203456bc964f2c8dc3 | chanyoonzhu/leetcode-python | /647-Palindromic_Substrings.py | 1,760 | 3.578125 | 4 | """
- dynamic programming
- O(n^2), O(n^2)
"""
class Solution:
def countSubstrings(self, s: str) -> int:
N = len(s)
res = 0
dp = [[False] * N for _ in range(N)] # dp[i][j] - if s[i:j+1] isPalindrom
for diff in range(N):
for l in range(N - diff):
... |
89d3c2f1909c7ae5f20b228a7604c8ae0b0b8901 | chanyoonzhu/leetcode-python | /amazon-Node_Distance.py | 1,466 | 3.84375 | 4 | class TreeNode(object):
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def nodeDistance(nums, x, y):
"""
:type root: TreeNode
:type p: TreeNode
:type q: TreeNode
:rtype: TreeNode
"""
def helper(nums, start, end):
if start > end:
... |
0ff43b369a3b5fa9e6b55539ca8f055824079d8f | chanyoonzhu/leetcode-python | /341-Flatten_Nested_List_Iterator.py | 1,790 | 4.15625 | 4 | # """
# This is the interface that allows for creating nested lists.
# You should not implement it, or speculate about its implementation
# """
#class NestedInteger:
# def isInteger(self) -> bool:
# """
# @return True if this NestedInteger holds a single integer, rather than a nested list.
# """... |
d37373595469ed6f2b052521efcb9581f16c6513 | chanyoonzhu/leetcode-python | /168-Excel_Sheet_Column_Title.py | 423 | 3.515625 | 4 | class Solution:
def convertToTitle(self, n: int) -> str:
"""
- a medium hard one, different from 26hex
"""
a = ord('A')
alphabet=[chr(i) for i in range(a,a+26)]
ans = ''
while n > 0:
n, r = divmod(n-1, 26) # n-1 is key
ans = a... |
5e15e0514f0a16a71e91054c87e3beecdccf5a74 | chanyoonzhu/leetcode-python | /827-Making_A_Large_Island.py | 1,944 | 3.875 | 4 | """
- dfs
- steps:
1. Explore every island using DFS, count its area, give it an island index and save the result to a {index: area} map. Note the grid elements are updated with their corresponding island index. Since the grid has elements 0 or 1. The island index is initialized with 2
2. Loop every cell == 0, ... |
38558b1b552138e2c0d22af68dfef316f0bba5dd | chanyoonzhu/leetcode-python | /199-Binary_Tree_Right_Side_View.py | 746 | 3.703125 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
"""
- bfs
- O(n), O(n)
"""
class Solution:
def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
... |
22e71e16482566ff1a54bf06d90e5522b982d260 | chanyoonzhu/leetcode-python | /515-Find_Largest_Value_in_Each_Tree_Row.py | 951 | 3.75 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
"""
- bfs
- O(n), O(n)
"""
class Solution:
def largestValues(self, root: Optional[TreeNode]) -> List[int]:
... |
7f27d7b5c49e21a9b4f5cd1b09bfa12cd028bc1a | chanyoonzhu/leetcode-python | /959-Regions_Cut_By_Slashes.py | 1,629 | 3.59375 | 4 | """
- dfs
- O(n * 2), O(n * 2)
"""
class Solution:
def regionsBySlashes(self, grid: List[str]) -> int:
"""
- intuition: convert this into an "island" problem: slashes are "water", find how many isolated islands
- approach: pixelate the n * n grid to 3n * 3n grid (why not 2n * 2n? be... |
db7098b4943f6d8cdfe321a21fa4aa1f53721d9e | chanyoonzhu/leetcode-python | /1574-Shortest_Subarray_to_be_Removed_to_Make_Array_Sorted.py | 833 | 3.6875 | 4 | class Solution:
"""
- two pointers
- algorithm:
1. pick qualifying prefix and suffix
2. merge prefix and suffix
"""
def findLengthOfShortestSubarray(self, arr: List[int]) -> int:
n = len(arr)
left, right = 0, n - 1
while left < n - 1 and arr[left] <=... |
0a99c4ab37785a0ff2ba423dc031c3ad4225d22c | chanyoonzhu/leetcode-python | /379-Design_Phone_Directory.py | 625 | 3.5 | 4 | """
- set
- O(1), O(n)
"""
class PhoneDirectory:
def __init__(self, maxNumbers: int):
self.available = set(range(maxNumbers))
def get(self) -> int:
if not self.available:
return -1
return self.available.pop()
def check(self, number: int) -> bool:
retur... |
4b4ec18338891b9258290eda47e7abfc3be9474b | chanyoonzhu/leetcode-python | /854-K-Similar_Strings.py | 508 | 3.703125 | 4 | """
- dynamic programming
- O(n^3), O(n^2)
"""
class Solution:
def kSimilarity(self, s1: str, s2: str) -> int:
return self.dp(s1, s2)
@lru_cache(None)
def dp(self, s1, s2):
if not s1:
return 0
if s1[0] == s2[0]:
return self.dp(s1[1:], s2[1:])
min_... |
eddcee01a2e7291c7142b3d370b95037882f3b77 | chanyoonzhu/leetcode-python | /373-Find_K_Pairs_With_Smallest_Sums.py | 2,995 | 3.640625 | 4 | from heapq import *
class Solution:
def kSmallestPairs(self, nums1, nums2, k):
"""
:type nums1: List[int]
:type nums2: List[int]
:type k: int
:rtype: List[List[int]]
"""
"""
O(n^2)
- brute force
if len(nums1) == 0 or ... |
96c33df297ff04e2ddb96c084ab6edd0dc35dcd8 | chanyoonzhu/leetcode-python | /179-Largest_Number.py | 732 | 3.734375 | 4 | """
- default comparator: Python2
- O(nlogn) for sorting, O(n)
"""
def compare(a, b):
if a + b > b + a: return 1
if a + b == b + a: return 0
return -1
class Solution:
def largestNumber(self, nums):
if not any(map(bool, nums)): return '0' # edge case: [0, 0] -> '0'
return ''.join(sorted(... |
a603c5d285d30c70d5562f66ac2d2c6f6de0a268 | chanyoonzhu/leetcode-python | /156-Binary_Tree_Upside_Down.py | 1,870 | 3.953125 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
"""
- Q: does every right node have a sibling?
- Q: how to handle children of right node? (no children on right node)
"""
"""
... |
a7e2d91d63f456967a0ea9e0cd5557782dd9c4be | chanyoonzhu/leetcode-python | /1547-Minimum_Cost_to_Cut_a_Stick.py | 958 | 3.625 | 4 | """
- dp (top-down):
dp[i][j] = minimum cost to achieve all the cuts between i and j
- O(n^3), O(n^2)
"""
class Solution:
def minCost(self, n: int, cuts: List[int]) -> int:
memo = {}
def dp(l, r):
if (l, r) not in memo:
memo[l, r] = min([dp(l, cut) + dp(cut, r) + (r ... |
822b4360a54f56d2fbbdea34fed6eb34287dcaa8 | chanyoonzhu/leetcode-python | /298-Binary_Tree_Longest_Consecutive_Sequence.py | 1,998 | 4.21875 | 4 | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
"""
Questions:
- validity of number (floats, negative integer and 0)
"""
"""
- top-down solution (pre-order traversal)
... |
21e423f42e990968fff2ee6c5c513d118fd00ba4 | chanyoonzhu/leetcode-python | /490-The_Maze.py | 1,112 | 3.546875 | 4 | class Solution:
"""
- dfs
- O(mn), O(mn)
"""
def hasPath(self, maze: List[List[int]], start: List[int], destination: List[int]) -> bool:
def get_next_pos_list(x, y):
i, j = x, y
res = []
for i, j in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
... |
6dc95ed21a229d0fb16c8353e3f82a0b6d25ae4e | chanyoonzhu/leetcode-python | /729-My_Calendar_I.py | 1,654 | 3.734375 | 4 | class Node:
def __init__(self, start, end):
self.start = start
self.end = end
self.left = None
self.right = None
def insert(self, node):
if node.start >= self.end:
if not self.right:
self.right = node
return True
... |
06829321ab86d508b0537566a80a986e7cca3bd4 | chanyoonzhu/leetcode-python | /218-The_Skyline_Problem.py | 3,927 | 3.53125 | 4 | import heapq
class Solution:
def getSkyline(self, buildings):
"""
- sweep lines: my solution
- O(nlogn), O(n)
- time limit exceeded
"""
def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]:
lines = []
for start, end, he... |
6f2fee840e507be746ed5005a69ab984c8cb37f0 | chanyoonzhu/leetcode-python | /amazon-High_Five.py | 1,007 | 3.53125 | 4 | """
There are two properties in the node student id and scores,
to ensure that each student will have at least 5 points,
find the average of 5 highest scores for each person.
"""
'''
Definition for a Record (for the exact problem online)
class Record:
def __init__(self, id, score):
self.id = id
... |
9d416afb64a32459d34b189d38388c5577e3ae78 | chanyoonzhu/leetcode-python | /275-H-Index_II.py | 832 | 3.65625 | 4 | """
- Better definition: The h-index is defined as the maximum value of h such that the given author/journal has published h papers that have each been cited at least h times.
"""
"""
- linear search
- O(n), O(n)
"""
class Solution:
def hIndex(self, citations: List[int]) -> int:
n = len(citations)
... |
cd4d514da386bc572ee4005a2db4ce48beec9423 | chanyoonzhu/leetcode-python | /102-Binary_Tree_Level_Order_Traversal.py | 801 | 3.765625 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
"""
- bst
- O(n), O(n)
"""
class Solution:
def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
if no... |
52cd4856936909289009bc6ce5c5b3c196a055f6 | chanyoonzhu/leetcode-python | /1691-Maximum_Height_by_Stacking_Cuboids.py | 852 | 3.875 | 4 | """
- dynamic programming
- similar: increasing subsequence with largest sum
- intuition: any compatible chain of cuboids can be transformed into another chain with the same cuboids, but each cuboid has its largest edge as the height w/o violating compatibility
"""
class Solution:
def maxHeight(self, cuboids: List[... |
1f667eda659a6e8237466143bb51527d2e46ca22 | chanyoonzhu/leetcode-python | /445-Add_Two_Numbers_II.py | 2,015 | 3.71875 | 4 | # Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution(object):
def addTwoNumbers(self, l1, l2):
"""
:type l1: ListNode
:type l2: ListNode
:rtype: ListNode
"""
"""
... |
0b587e6dcc500d72d87758746cbb88caf9f1bbf8 | chanyoonzhu/leetcode-python | /981-Time_Based_Key_Value_Store.py | 1,932 | 3.65625 | 4 | from collections import defaultdict
"""
- Clarification questions:
Q: Do the timestamps keep increasing? A: Yes.
Q: Is it strict increasing? A: Yes
- Follow-up question:
Q: What if the timestamps is increasing but not strictly increasing?
"""
class TimeMap:
"""
- binary search: and hashmap
- set: O(1), O(... |
49c7cad869a39bb6dad0074d778eee0de3f0d2f5 | chanyoonzhu/leetcode-python | /2092-Find_All_People_With_Secret.py | 1,380 | 3.578125 | 4 | """
- Union Find
"""
class Solution:
def findAllPeople(self, n: int, meetings: List[List[int]], firstPerson: int) -> List[int]:
time_to_meetings = defaultdict(set)
for x, y, time in meetings:
time_to_meetings[time].add((x, y))
uf = UnionFind(n)
res = [0]
... |
5140b833dd3e39a2e5d99adadbfa460466f8b41b | chanyoonzhu/leetcode-python | /285-Inorder_Successor_in_BST.py | 1,571 | 3.6875 | 4 | """
- bst
- O(log(n))
"""
class Solution:
def inorderSuccessor(self, root: 'TreeNode', p: 'TreeNode') -> 'Optional[TreeNode]':
if not root:
return None
if root.val > p.val:
closer_successor = self.inorderSuccessor(root.left, p)
return closer_successor if closer_s... |
958e6570050dfb2fa7737fa672b0c3350aa0c7db | chanyoonzhu/leetcode-python | /124-Binary_Tree_Maximum_Path_Sum.py | 1,046 | 3.953125 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
"""
- dfs
- clarification: definition of path is tricky: path with no fork, does not need to go through root nor leaf
- O(n), O... |
e645adb758b4f4565b5ef80e6aaad927f598939b | chanyoonzhu/leetcode-python | /655-Print_Binary_Tree.py | 1,171 | 3.90625 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
"""
- dfs
- O(n), O(n)
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, ri... |
5e8f6581f31559d5b9964727433147f9c9b7f1b7 | chanyoonzhu/leetcode-python | /065-Valid_Number.py | 2,211 | 4.0625 | 4 | """
- string parsing
- key:
If char == + or char == -, then prev char (if there is) must be e
. cannot appear twice or after e
e cannot appear twice, and there must be at least one digit before and after e
All other non-digit char is invalid
"""
"""
examples:
valid: ["2", "0089", "-0.1", "+3.14", "4.", ... |
1658ad6112cc5a5d827c3149e689ac790e67be1a | chanyoonzhu/leetcode-python | /029-Divide_Two_Integers.py | 1,087 | 3.921875 | 4 | """
- bitwise operations
- intuition: when multiplication and division cannot be used, we can use addition and subtraction. Linear subtraction is slow, can subtract power
- eg: (remaining dividend, substract_count): (20, 0) -> (20 - 2 ^ 0 * 3 = 17, 1) -> (17 - 2 ^ 1 * 3=11, 3) -> (11 - 2 ^ 2 * 3 = -1, 3)cannot be neg, ... |
78bfafd308856dd5d638b2ea0a9c70aafac56829 | chanyoonzhu/leetcode-python | /010-Regular_Expression_Matching.py | 1,699 | 3.578125 | 4 | """
- edge cases:
(ab, c*ab) => True c* can match empty string
"""
"""
- dynamic programming (top-down)
- O(sp), O(sp)
"""
class Solution:
def isMatch(self, s: str, p: str) -> bool:
return self.match(s, p)
@lru_cache(None)
def match(self, s, p):
if not p:
return not s
... |
71a2a8cd32b29d8166a1400fb497b28a46bf752e | chanyoonzhu/leetcode-python | /1402-Reducing_Dishes.py | 557 | 3.671875 | 4 | """
- greedy
- O(n), O(1)
- intuition: start from the dish with the largest satisfaction, insert if do not bring down overall value
"""
class Solution:
def maxSatisfaction(self, satisfaction: List[int]) -> int:
satisfaction.sort(reverse=True)
result = _sum = 0
for s in satisfaction:
... |
5ec068e9212e066a8e80cb39405d25e7e01e261d | chanyoonzhu/leetcode-python | /236-Lowest_Common_Ancestor_of_A_Binary_Tree.py | 2,828 | 3.8125 | 4 | import collections
# Definition for a binary tree node.
class TreeNode(object):
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
"""
- hashmap + set: keep a map of child to parent, and a set for all parents of p, search if parents for q fr... |
cd42c97427ddb600e9a722607afff845b52223e3 | chanyoonzhu/leetcode-python | /024-Swap_Nodes_in_Pairs.py | 694 | 3.640625 | 4 | # Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def swapPairs(self, head: ListNode) -> ListNode:
origin = ListNode(0)
origin.next = head
ptr = origin
while ptr.next:
... |
a6ccdc1d7130862baedab7e5f25fe61808b3c1db | chanyoonzhu/leetcode-python | /1627-Graph_Connectivity_With_Threshold.py | 878 | 3.625 | 4 | """
- union find
"""
class Solution:
def areConnected(self, n: int, threshold: int, queries: List[List[int]]) -> List[bool]:
parents = [i for i in range(n + 1)]
def find(x):
if parents[x] != x:
parents[x] = find(parents[x])
return parents[x]
... |
af6145641ca1bb6d19153a344b0ed7ea921997d9 | MaximSungmo/practice02 | /prob04.py | 561 | 3.609375 | 4 | # ๋ฌธ์ 4 ๋ฐ๋ณต๋ฌธ์ ์ด์ฉํ์ฌ 369๊ฒ์์์ ๋ฐ์๋ฅผ ์ณ์ผ ํ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ์์๋๋ก ํ๋ฉด์ ์ถ๋ ฅํด๋ณด์ธ์. 1๋ถํฐ 99๊น์ง๋ง ์คํํ์ธ์.
min = 1
max = 100
*numbers, = range(min, max+1)
conditions = (3, 6, 9)
print(numbers)
for number in numbers:
clap_count = 0
i = number
flag = True
while(flag):
if i%10 in conditions:
clap_count += 1
... |
2b73f00dfd5cf7b780c2da889d0f05ac449e31b3 | XQ96/huawei_online_programming | /.idea/7.py | 331 | 3.53125 | 4 | # -*- coding:utf-8 -*-
# @Author:xuqi
# @time:2019/3/7 19:09
# @File:7.py
import math
def get_value(a):
a=float(a)
decimal=a-int(a)
if (decimal*10)>=5:
return math.ceil(a)
else:
return math.floor(a)
if __name__=='__main__':
case=input()
print(get_value(case))
#math.ceil()
#ma... |
58cc753bde9be33f278476685fc4cbcfd6dee880 | dblueblood/ROLL-THE-DICE | /HOGGIE.py | 528 | 3.921875 | 4 | MAGIC = "hogwarts"
Guess = " "
GuessCT = 0
GuessLMT = 3
G_O = False
""""
infinite loops area possibility in the creation of "while" loops
"""
while Guess != MAGIC and not G_O:
if GuessCT < GuessLMT:
Guess = input("Where was Dumbledore killed?\nYou have " + str(GuessCT + 1) + " of 3 attempts left... |
0b27c85793e05386e432083fa3c92970c5f98c75 | AidanH6/PythonBeginnerProjects | /8ball.py | 1,267 | 3.640625 | 4 | import random
import time
replies = [ "It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely",
"You may rely on it.",
"As I see it yes.",
"Most likely.",
"Outlook good.",
"Yes.",
... |
ada8ece51784a9a0db19a68135de2187fc416419 | Deep-Lan/Neural-Network | /neuralnetwork.py | 6,682 | 3.828125 | 4 | import numpy as np
import random
import matplotlib.pyplot as plt
def sigmoid(z):
return 1 / (1 + np.exp(-z))
class NeuralNetwork(object):
def __init__(self, cell_num_list):
"""
:param cell_num_list: a list,each element is cell number of every layer.
For example,[4, 10, 3... |
14f3446ba3484d9aadd407c666e59499342d7654 | hpec/ok | /client/protocols/scoring.py | 3,491 | 3.5 | 4 | """Implements the ScoringProtocol, which runs all specified tests
associated with an assignment.
"""
from client.models import core
from client.protocols import grading
from client.utils import formatting
from collections import OrderedDict
#####################
# Testing Mechanism #
#####################
class Scor... |
d764309608c95ad149d6967901c6fddfdf17b9eb | stefanodem/Data-Structures | /heap/heap.py | 2,931 | 3.640625 | 4 | class Heap:
def __init__(self):
self.storage = []
def insert(self, value):
self.storage.append(value)
self._bubble_up(len(self.storage) - 1)
def delete(self):
if len(self.storage) == 1:
return self.storage.pop()
max_el = self.get_max()
self.storage[0] = self.storage.pop()
self... |
40b68d88f144f803058b99b80807bf89005b9acf | footmessithanos/Little_Inventors_Assignments_Folder | /Advaith/dictionary.py | 283 | 3.8125 | 4 | phonebook ={'Advaith.Y': 'Future kids',\
'Advaith.B': 'Dehli Public',\
'Tanishq' : 'Sancta Maria', \
'Jainam' : 'Oakridge', \
'Amogh' : 'Manthan', \
'Vidit' :'Shri Ram'}
print(phonebook)
a = input("Whoose school do you want to find ")
print("The school is", phonebook[a]) |
5cd8b74f1d8d309b1555b4c7170e954aeb7973b8 | jzmnd/time-series-templates | /minmax_scaling.py | 3,620 | 3.640625 | 4 | """A min-max scaling model for time series data"""
import numpy as np
from statsmodels.regression.linear_model import OLS
from statsmodels.tools.tools import add_constant
class MinMaxScaling():
"""A min-max scaling model for time series data.
The model is suitable for seasonal data in which there is a clear ... |
15a967200acede557583b34626d7119df92535b8 | tommyphan8/verdant-octo-sniffle | /anagram.py | 782 | 3.671875 | 4 |
#O(n^2)
def anagram(a, b):
temp = list(b)
posA = 0
contSearch = True
while(posA < len(a) and contSearch):
posB = 0
found = False
while(posB < len(b) and not found):
if a[posA] == temp[posB]:
found = True
else:
posB += 1
... |
e4fa1c600cfb3a6fc214d6baba6b37d6322ab27d | tommyphan8/verdant-octo-sniffle | /Trees/tree.py | 821 | 3.890625 | 4 | #Tree implementation of
def BinaryTree(r):
return [r, [], []]
def insertLeft(root, newBranch):
t = root.pop(1)
newNode = [newBranch, [],[]]
if len(t) > 0:
newNode[1] = t
root.insert(1, newNode)
else:
root.insert(1,newNode)
return root
def insertRight(root, newBranch):
t = root.pop(2)
newNode = [newB... |
62ceb147e7c6ea9f1dc5fbec2e4e6c1d8dbe75f2 | tommyphan8/verdant-octo-sniffle | /bubbleSort.py | 951 | 3.75 | 4 | def bubbleSort(l):
for x in range(len(l)-1):
for y in range(len(l)-1-x):
if l[y] > l[y+1]:
temp = l[y]
l[y] = l[y+1]
l[y+1] = temp
a = [4,3,1,8,9,2,15,14,6]
#shortBubbleSort
#Input: a list
#sorts using bubble sort, however if there are no swap... |
9d6f55d48f34fa7fa7c7743a12469942ca6e2bc6 | tommyphan8/verdant-octo-sniffle | /hashTable.py | 1,983 | 3.765625 | 4 | class HashTable:
def __init__(self):
self.size = 11
self.key = [None] * self.size
self.value = [None] * self.size
def put(self, key, val):
hashValue = self.hashFunction(key)
if self.key[hashValue] == None:
self.key[hashValue] = key
self.value[has... |
0ff65b78072fe6e987eaabf65fd19878a7fadf25 | lgope/python-world | /crash-course-on-python/week-4/dict.py | 1,178 | 3.796875 | 4 | # dict are mutable (add, remove, replace are allowed)
file_counts = {'jpg': 10, 'txt': 14, 'csv': 2, 'py': 23}
print(file_counts)
print(file_counts['txt'])
print('jpg' in file_counts)
print('html' in file_counts)
file_counts['cfg'] = 8
print(file_counts)
file_counts['csv'] = 17
print(file_counts)
del file_count... |
edb32fd06af6757fd99560e93bc66363531a8f8d | lgope/python-world | /crash-course-on-python/week-1/module_1_graded_assessment.py | 1,338 | 4.28125 | 4 | # 6. Write a Python script that outputs "Automating with Python is fun!" to the screen.
print("Automating with Python is fun!")
# Question 7 Fill in the blanks so that the code prints "Yellow is the color of sunshine".
color = "Yellow"
thing = "sunshine"
print(color + " is the color of " + thing)
# Question 8 Keepin... |
52fea091a1c4de9f8383b15e13f61b2109d1d934 | lgope/python-world | /crash-course-on-python/week-2/module_2_graded_assessment.py | 4,094 | 4.4375 | 4 | # Question 1
# Complete the function by filling in the missing parts. The color_translator function receives the name of a color, then prints its hexadecimal value. Currently, it only supports the three additive primary colors (red, green, blue), so it returns "unknown" for all other colors.
def color_translator(color... |
e4f6cad9f69235be1828265bce12c6fad7c484d4 | lgope/python-world | /crash-course-on-python/week-2/quiz_conditionals.py | 1,940 | 4.28125 | 4 | # Question 2
# Complete the script by filling in the missing parts. The function receives a name, then returns a greeting based on whether or not that name is "Taylor".
def greeting(name):
if name == "Taylor":
return "Welcome back Taylor!"
else:
return "Hello there, " + name
print(greeting("Taylor"))
p... |
7a0a1ec188c05c5d5ae18985a0feeaa6f5950bfa | palSitabja/Machine_Learning | /leastSquare.py | 946 | 3.84375 | 4 | ## @Sitabja Pal, 20/9/2018, Simple Linear Regression by Least Square Method ##
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
def minSquare(x,y,x_mean,y_mean,n):
num,denom=0,0
for i in range(n):
num+=(x[i]-x_mean)*(y[i]-y_mean)
denom+=(x[i]-x_mean)**2
m=num/d... |
9c8c77c34cad2d40949947bcf287b3258f75eb26 | darshanmest47/keypresspatterns | /pattern5.py | 349 | 3.65625 | 4 | spaces =4
spaces2=4
for k in range(1,2):
print(spaces2*" "+k*'*'+spaces2*" ")
for i in range(1,6):
print(spaces*" "+(i*2)*"*"+spaces*" ")
spaces = spaces-1
spaces1= 0
for j in range(5,0,-1):
print((spaces*1)*" " + (j*2) * "*"+(spaces*1)*" ")
spaces = spaces+1
for k1 in range(1,2):
print(sp... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.