blob_id stringlengths 40 40 | repo_name stringlengths 5 127 | path stringlengths 2 523 | length_bytes int64 22 545k | score float64 3.5 5.34 | int_score int64 4 5 | text stringlengths 22 545k |
|---|---|---|---|---|---|---|
802aed8b41a4c1e84af04ed21d3f5a6be4632ef3 | walthari/C-ex | /test.py | 1,727 | 3.84375 | 4 | # if, for Statements and other stuff
words = ['dog', 'window', 'international']
for w in words:
print(w, len(w))
for w in words[:]:
if len(w) > 6:
words.insert(0, w)
print(words)
# range Function
x = ['Mary', 'had', 'a', 'little', 'lamb']
for i in range(len(x)):
print(i, x[i])
# Loops: break,... |
244c4f19dfe68f54ba6c67def1b92f2d7a9bf8f0 | Chen-Jialin/SI100B-Introduction-to-Infomation-Science-and-Technology-Assignments | /Homework_4/Homework_4.py | 5,032 | 4 | 4 | import sys
Map = sys.stdin.read()#get the input
Map = Map.split('\n')#transform the data from string to list, each line to an element in the list
if len(Map) <= 0:#if the input is empty
exit(0)#exit
i = 0
while i < len(Map):#skip the comments in the input
if '$' in Map[i] or Map[i] == '':#if the line is comme... |
93bb555f229ba3666383a3ed984e14c8df648627 | shantanu609/Leetcode | /convert-binary-number-in-a-linked-list-to-integer/convert-binary-number-in-a-linked-list-to-integer.py | 438 | 3.609375 | 4 | # Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def getDecimalValue(self, head: ListNode) -> int:
node = head
num = 0
while node:
num = num * 10 + no... |
17cc48f09f13c0534650eead06c7fe958436c887 | shantanu609/Leetcode | /valid-palindrome/valid-palindrome.py | 659 | 3.59375 | 4 | class Solution:
def isPalindrome(self, s: str) -> bool:
string = []
for i in range(len(s)):
ch = s[i]
if ch.isdigit():
string.append(ch)
elif ch.isalpha():
string.append(ch.lower())
else:
continue
... |
3251099a9f2a9b646a8a052cf497cb753b396481 | shantanu609/Leetcode | /shortest-word-distance/shortest-word-distance.py | 507 | 3.609375 | 4 | class Solution:
def shortestDistance(self, wordsDict: List[str], word1: str, word2: str) -> int:
d = {}
for i in range(len(wordsDict)):
word = wordsDict[i]
if word not in d:
d[word] = []
d[word].append(i)
... |
8cf955be282daf486757458ebfa1d5f516289cac | shantanu609/Leetcode | /number-of-provinces/number-of-provinces.py | 1,000 | 3.53125 | 4 | class DSU:
def __init__(self, size):
self.parent = [i for i in range(size)]
def find(self, num):
if self.parent[num] != num:
self.parent[num] = self.find(self.parent[num])
return self.parent[num]
def union(self, num1, num2):
self.parent[self.find(nu... |
b13f3c920cf338ee011f4768d3008b3b69629f46 | shantanu609/Leetcode | /all-possible-full-binary-trees/all-possible-full-binary-trees.py | 1,020 | 3.734375 | 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
class Solution:
memo = None
def allPossibleFBT(self, n: int) -> List[TreeNode]:
self.memo = {0 : [], 1 ... |
cedba63bb5caae1cbeafac09cbefba51c6b79da8 | shantanu609/Leetcode | /letter-case-permutation/letter-case-permutation.py | 1,131 | 3.65625 | 4 | class Solution:
def letterCasePermutation(self, s: str) -> List[str]:
self.res = set()
self.backtrack(list(s), 0, [])
return list(self.res)
def backtrack(self, s, indx, path):
# base case
if indx == len(s):
if len(path) == len(s):
self.r... |
306b0996390a7d356a55cc3881836e358b7643af | shantanu609/Leetcode | /construct-binary-tree-from-preorder-and-inorder-traversal/construct-binary-tree-from-preorder-and-inorder-traversal.py | 1,631 | 3.9375 | 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
class Solution:
def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode:
""" i
... |
7aef01d675b4ef584bbfa692f73535f0465ae10c | shantanu609/Leetcode | /add-digits/add-digits.py | 241 | 3.53125 | 4 | class Solution:
def addDigits(self, num: int) -> int:
if num == 0:
return 0
if num % 9 == 0:
return 9
return num % 9
"""
10 = 9 + 1
100 = 99 + 1
1000 = 999 + 1
""" |
a4c7b5a72d0d005b1f002b1a063d4623174a1150 | shantanu609/Leetcode | /minimum-number-of-refueling-stops/minimum-number-of-refueling-stops.py | 1,445 | 3.71875 | 4 | import heapq
class Solution:
def minRefuelStops(self, target: int, startFuel: int, stations: List[List[int]]) -> int:
"""
10 stations = [[10,60],[20,30],[30,30],[60,40]] target = 100
i
... |
3aae661ed3c322893712aa994abbc2e18d84854c | shantanu609/Leetcode | /binary-tree-paths/binary-tree-paths.py | 1,016 | 3.53125 | 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
class Solution:
res = None
def binaryTreePaths(self, root: TreeNode) -> List[str]:
if not root:
ret... |
99aa4ce08918fd8376a56c46b2ff339b77d69e77 | shantanu609/Leetcode | /convert-binary-search-tree-to-sorted-doubly-linked-list/convert-binary-search-tree-to-sorted-doubly-linked-list.py | 1,056 | 3.90625 | 4 | """
# Definition for a Node.
class Node:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
"""
"""
pred = left pointer
succ = right pointer
"""
class Solution:
def treeToDoublyList(self, root: 'Node') -> 'Node':
if not root... |
35d8e914f16c241ba2df3fa078f6e4140f48c9a2 | shantanu609/Leetcode | /stream-of-characters/stream-of-characters.py | 1,308 | 3.734375 | 4 | class TrieNode:
def __init__(self):
self.childrens = {}
self.isEnd = False
class Trie:
def __init__(self):
self.root = TrieNode()
def insert(self, word):
node = self.root
for i in range(len(word)-1, -1, -1):
char = word[i]
if char not ... |
cfaba8daee367c290617648640820d5f4b92f990 | shantanu609/Leetcode | /construct-binary-search-tree-from-preorder-traversal/construct-binary-search-tree-from-preorder-traversal.py | 734 | 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
class Solution:
def bstFromPreorder(self, preorder: List[int]) -> TreeNode:
return self.helper(preorder)
de... |
891be5845496c4548b548b9f7eefc2f589918155 | shantanu609/Leetcode | /delete-nodes-and-return-forest/delete-nodes-and-return-forest.py | 1,071 | 3.734375 | 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
class Solution:
res = None
def delNodes(self, root: TreeNode, to_delete: List[int]) -> List[TreeNode]:
to_delet... |
8fde712d6f525b47c1989497f3dbd086c61c7041 | SAMLEVENSON/ACET | /Factorialwi.py | 233 | 4.125 | 4 | def main():
print("To find the Factorial of a Number")
a= int(input("Enter the Number:"))
if(a>=20)
fact =1
for i in range(1,a + 1):
fact = fact*i
print(fac)
if __name__ == '__main__':
main()
|
6b7f55eac7ce0f0fa0318dae28e292e8ad529101 | SAMLEVENSON/ACET | /Prime or notprime.py | 306 | 3.890625 | 4 | def main():
print("To check whether a prime number or not")
a=int(input("Enter a Number To check:"))
if a>1:
for i in range(2,a):
if(a%i)==0:
print ("No")
break
else:
print ("yes")
break
if __name__ == '__main__':
main()
|
5729a8702d330323813828cd359c82f68bc73282 | cassiel/motor-mix | /python/display.py | 2,671 | 3.703125 | 4 | """
Overall display, to curses console and device LCD.
"""
class Display:
def __init__(self):
self.labelStore = [[" " for _ in range(8)] for _ in range(8)]
def setupLabels(self, row, labels):
"""
>>> d = Display()
>>> def toScreen(r, c, text): print(f"[toScreen {r} {c} |{tex... |
ac7ae08a79554e772469bb0b1c64dcc2524a159b | KipiLearn/DataStructure-Python | /Insertionsort.py | 359 | 4.03125 | 4 | # Insertion sort program using Python
def InsertionSort(lst):
for i in range(1,len(lst)):
ele=lst[i]
position=i
while ele < lst[position-1] and position > 0 :
lst[position]=lst[position-1]
position=position-1
lst[position]=ele
list1=[20,40,30,50,10,60... |
efdd6868431249afa1d24512f294622af8dac390 | xxyLiang/python | /other/listnode.py | 3,611 | 3.796875 | 4 | class ListNode:
def __init__(self, val) -> None:
self.val = val
self.next = None
def k_reverse(head, k):
# k个一组反转链表
node = head
for i in range(k):
if node is None:
return head
node = node.next
res = reverse(head, node)
head.next... |
efcf6cb29630dc66b7fef11c1ee061c7ebd18909 | xxyLiang/python | /other/tree.py | 4,347 | 3.734375 | 4 | from typing import List
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def levelOrder(root: TreeNode) -> List[List[int]]:
'''
按层遍历二叉树,返回[ [第一层], [第二层], ...]
'''
que, res = [], []
if not root: # 根节点为空直接返回
... |
b93ecdb5f9f87843d1393cbeebc2992b49fc07b6 | Itachiia/Python_practice | /hazy.py | 4,679 | 3.703125 | 4 | class Function () :
def __init__ (self) :
self.humidty = 0
self.temperature = 0
self.temperature_degree = []
self.humidty_degree = []
self.min_time_short = []
self.min_time_middle = []
self.min_time_long = []
self.max_time_short = []
self.max_time_middle = []
self.max_time_long = []
self.result =... |
a85b5485cdb69186476246caad19a49d11c2fb71 | ProgrammingFriday/Live | /Euler/031.py | 416 | 3.75 | 4 |
money = [ 1, 2, 5, 10, 20, 50, 100, 200 ]
coins = money.reversed()
def solve(goal, current=0):
n = 0
if current >= goal:
return True
for coin in money:
if current + coin == goal:
n += 1
else:
n += solve(goal, current + goal)
return n
def solve2(goal, coins, index):
i = 0
while... |
0a86adc558cd6d8a82342a4cd0710049ee77fa60 | mdoprog/Warehouse | /Python/basics/salary_calc.py | 273 | 3.703125 | 4 | # coding=utf8
#Entrada
sal_hora = float (input("Quanto você ganha por hora? "))
horas_trab = int (input("Quantas horas você trabalhou neste mês? "))
#Processamento
salario = sal_hora * horas_trab
#Saída
print("Neste mês você vai receber R$ {0:.2f}".format(salario)) |
d21de75d7e713515b0b97ba77122451773e628da | mdoprog/Warehouse | /Python/loops/higher_small_average_number.py | 536 | 3.8125 | 4 | # coding=utf8
maior = -999
menor = 999
soma = 0
#Entrada / Processamento
print("Informe dez números positivos: ")
for i in range (1, 11):
num = int (input())
#Processamento
while num < 0:
#Entrada
num = int (input("Informe um número positivo: "))
if num > maior:
m... |
09a4cbaa1adf16e810e99ed52ed60f53166c3005 | mdoprog/Warehouse | /Python/arrays/array_sum1.py | 292 | 3.71875 | 4 | # coding=utf8
# Declaração
vetor = []
# Entrada
for n in range(0,20):
num = int (input("Informe {0}/20 valor para o vetor: ". format(n + 1)))
vetor.append(num)
print("\nVetor: ", end = '')
for i in vetor:
print(i, end = " ")
print("\nA soma do vetor é {0}".format(sum(vetor))) |
fe09f0b806e831dc49f2775511090d69af293be6 | GeorgeChai/Liner_SVM | /hyperplane.py | 420 | 3.5 | 4 | import matplotlib.pyplot as plt
import numpy as np
def hyperplane(w,b,start,end):
x_points = np.linspace(start, end, 2)
y_ = -(w[0] * x_points + b) / w[1]
y_plus = -(w[0] * x_points + b + 1) / w[1]
y_sub = -(w[0] * x_points + b - 1) / w[1]
plt.plot(x_points, y_)
plt.plot(x_points, y_plus, lin... |
58fce997d6225bf04b1a70ab0c215385e240cd3a | fedor-11/tinkoff | /investKTrac.py | 1,551 | 3.546875 | 4 | import csv
def csv_reader(file_obj):
"""
Read a csv file
"""
reader = csv.reader(file_obj)
i = 0
prices = []
time = []
data = []
for row in reader:
if i >= 1:
prices.append(float(row[-1]))
time.append(row[-2][:4])
data.append(row[-3])
... |
081660185ddd672a502b7ed045323b71fdc71421 | wd6/Interesting-and-Simple-Python-Projects | /1.Countdown-clocker.py | 732 | 3.96875 | 4 | import time
total_time = 0
while True:
try:
print("\n")
total_minutes = float(input("Please input the minutes: \n")) # 输入倒计时分钟数
total_seconds = int(total_minutes * 60) # 转为秒数
total_time += total_seconds
starttime = time.time() # 当前时间
print('Started')
current =... |
92361d35969abefc2ed748dac52174c43a75a559 | larryklean/Erwin | /foundations/装饰器/decorator.py | 920 | 3.765625 | 4 | import time
# 函数是一个对象,可以把函数当作参数传递给一个变量进行调用
def func():
l = []
for i in range(1, 10):
l.append(i)
print(l)
# 可以通过属性 __name__ 来获取函数的名称
f = func
# print(f.__name__)
# 装饰器 在运行期间不修改代码动态增强函数功能
# def log(func,text):
# def wrapper(*args, **kwargs):
# print("call %s() %s" % (func.__name__... |
43a0605f9987fc3600826dcbb9ae7a79aa0de894 | larryklean/Erwin | /foundations/mountain_poll.py | 715 | 3.75 | 4 | responses = {}
polling_active = True
while polling_active:
name = input("please input your name: ")
response = input("which mountain would you like to climb someday?: ")
responses[name] = response
repeat = input("would you want to let another person respond?")
if repeat == 'no':
break
f... |
aa35d8d785024681f35c366f8680cdc915f0d5ee | larryklean/Erwin | /foundations/func.py | 210 | 3.71875 | 4 | # def func():
# print("hello")
# return "hello"
#
#
# def func2():
# print("world")
#
#
# x = func()
# y = func2()
#
# print("The result of func is %s" % x)
# print("The result of func2 is %s" % y)
|
701c18863d6ab6b787dbf6c4494c820ecb5cc183 | larryklean/Erwin | /foundations/func_return.py | 364 | 3.796875 | 4 | # def calc_sum(*args):
# sum = 0
# for i in args:
# sum += i
# return sum
# sum = calc_sum(1, 2, 3, 4)
# print(sum)
def calc_sum(*args):
def sum():
ax = 0
for item in args:
ax += item
return ax
return sum
func1 = calc_sum(1, 2, 3, 4)
func2 = calc_sum... |
7e5e1538aec62a7fe17ac1657eb6235edc8f3d84 | larryklean/Erwin | /foundations/set.py | 521 | 4 | 4 | list_1 = [1, 2, 3, 4, 5, 4, 5, 6, 3]
list_2 = [3, 2, 9, 7]
list_1 = set(list_1)
list_2 = set(list_2)
# 交
print(list_1.intersection(list_2))
# 并
print(list_1.union(list_2))
# 差
print(list_1.difference(list_2))
print(list_2.difference(list_1))
# 子集判断
print(list_1.issubset(list_2))
# 父集判断
print(list_1.issuperset(list_2)... |
21a6fa88ac77cc7acae97f0e1a24e3b5ab420d9e | adelyalbuquerque/projetos_adely | /exercicios_listas/vetor_numeros_inteiros.py | 144 | 3.9375 | 4 | lista_numeros = []
while len(lista_numeros) < 5:
lista_numeros.append(input("Insira um numero inteiro: ".format(i)))
print(lista_numeros)
|
5a4ec980dee88ccbbf145b1c4bcc6de203ea2648 | adelyalbuquerque/projetos_adely | /gasolina_alcool.py | 888 | 3.515625 | 4 | def preco_desconto_gasolina_alcool(litros, combustivel):
if combustivel == "A":
if litros <= 20:
gasto = (litros * 1.90) - (litros * 0.03) * 1.90
print "Valor a ser pago: {}".format(gasto)
else:
gasto = (litros * 1.90) - (litros * 0.05) * 1.90
print "V... |
63c49cd9cc64bfbaa471cfe06e10071ca8f82ca0 | adelyalbuquerque/projetos_adely | /numeros.py | 337 | 4.125 | 4 | def maior_numero():
primeiro_numero = float(raw_input("Digite o primeiro numero: "))
segundo_numero = float(raw_input("Digite o segundo numero: "))
if primeiro_numero > segundo_numero:
print "Maior numero: {}".format(primeiro_numero)
else:
print "Maior numero: {}".format(segundo_numero)... |
26e8e5d133d61fabe41ea4dc4d119ebced6274f9 | mitakaxqxq/Python101 | /Week2/test_collect_fractions.py | 2,967 | 3.5 | 4 | import unittest
from collect_fractions import validate_values,collect_fractions,LCM,check_zero_denominator,check_fraction_length_bigger_than_required,check_fraction_length_lower_than_required
class TestValidateValues(unittest.TestCase):
def test_input_if_it_is_given_as_tuple_of_tuples(self):
exc = None
... |
cbf8181e14f8f7ba297e5772c7e52fa11727ab34 | mitakaxqxq/Python101 | /Week3/MusicLibrary/test_playlist.py | 6,207 | 3.5625 | 4 | import unittest
from song import Song
from playlist import Playlist
class TestValidationOfPlaylistArguments(unittest.TestCase):
def test_when_playlist_name_is_not_string(self):
exc = None
try:
p = Playlist(123)
except Exception as err:
exc = err
... |
f839e05c75c249ee9c70e47662f4df639593b8c6 | mitakaxqxq/Python101 | /Week3/Polynomials/solution.py | 354 | 3.53125 | 4 | import sys
from utils import break_down_into_list_of_strings,convert_string_to_term,convert_string_into_polynomial
def main():
args = sys.argv[1]
myPolynomial = convert_string_into_polynomial(args)
print('The derivative of f(x) = '+args+' is:')
print('f`(x) = ' + myPolynomial.derivative())
if ... |
1ac69137e8dfe6c442518e5e0a9e3415e3496834 | Amazon-Lab206-Python/Todd_Enders | /Demos/person.py | 620 | 3.8125 | 4 | class Person(object):
def __init__(self, age, name):
self.age = age
self.name = name
def talk(self, phrase):
print phrase
return self
def code(self):
print "I've been coding for {} years".format(self.age)
return self
p1 = Person(33, "Todd")
p2 = Per... |
53ce875f1d28ff7013d9d08d343648d251ebdba0 | Amazon-Lab206-Python/Todd_Enders | /Demos/coin_tosses.py | 659 | 3.96875 | 4 | import random
def cointosses():
# flip a coin 5,000 times
heads = 0
tails = 0
for toss in range(10):
# how to determine head or tail
# let's make a head 0 and a tail 1
result = random.randint(0,1)
# if we get a head or a 0, increment the head count
if (result == ... |
4e92017cf0ea7595a7860f87b77a0c1be2f63a05 | Amazon-Lab206-Python/Todd_Enders | /Fundamentals/type_list.py | 749 | 3.84375 | 4 | ml = ['magical unicorns',19,'hello',98,'world']
il = [2,3,1,7,4,12]
sl = ['magical','unicorns']
testlist = sl
sum = 0
phrase = ""
listtype = None
for val in testlist:
if (type(val) is int):
sum += val
if (listtype is "string"):
listtype = "mixed"
elif (listtype is None):
... |
ca8a0f57637bea833a43d0e577338d44444897ef | longroad41377/iteration | /age.py | 378 | 4.09375 | 4 | while True:
try:
age = int(input("Enter the student's age (16-30):"))
if age >= 16 and age <= 30:
print("Age of {0} has been accepted by the system as valid".format(age))
else:
print("Age of {0} has not been accepted by the system".format(age))
except Excep... |
c963580cb28a4eda3dd84452b650b850843d0d1a | longroad41377/iteration | /total.py | 285 | 4.0625 | 4 | total = 0
number_count = int(input("Please enter the number of numbers in the series: "))
for counter in range(number_count):
total += int(input("Please enter number {0} in the series: ".format(counter)))
print("The total of the numbers you entered is {0}".format(total))
|
7b73548582f8050b1920c577ccf07424173a4cb1 | bhavanakv/basics-of-flask | /session.py | 1,024 | 3.5 | 4 | from flask import Flask, session, redirect, url_for, request
app = Flask(__name__)
app.secret_key = 'SecretKey'
@app.route("/log")
def basic():
return "Succesfully logged out!"
@app.route("/session")
def index():
if 'username' in session:
username = session['username']
return "Logged in as" + ... |
d705565928df16e4c1e2072c8ef8c083b707ac67 | Mr-wang-1/Leetcode-python | /Leetocde173.py | 1,359 | 3.90625 | 4 | # Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class BSTIterator:
def __init__(self, root: TreeNode):
# O(h)内存,说明要用栈,不能使用队列等结构
self.stack = []
# 将左子节点依次入栈
self._left_i... |
ae3b2ca730b9de7350e7a2dac5565eed31e1d726 | Mr-wang-1/Leetcode-python | /coinsRoad.py | 586 | 3.5625 | 4 |
def coinsRoad(result):
import numpy as np
road = a=np.zeros((5,6))
i = len(f)-1
j =len(f[0])-1
while(j>=0 and i>=0):
if f[i-1][j]==f[i][j-1]:
road[i-1][j] = 1
road[i][j-1] = 1
i = i-1
j = j-1
elif f[i-1][j]>f[i][j-1]:
road... |
355229426ba0a0cfc59bdbe4b76106a186775ffb | Mr-wang-1/Leetcode-python | /whatCollections.py | 550 | 3.84375 | 4 | # 关于python 中 collectionmo模块的学习
from collections import *
# 命名元组(namedtuple)是元组和字典的混合体,他赋予每个元素含义(字典的特性),而且元素不可修改(元组的特性)
# 创建命名元组需要设定两个必须参数:元组名称,字段名称
# Final Product FP
FP=namedtuple('FP',['assect','instrument'])
print(FP) #<class '__main__.FP'>
product = FP('FX','European Option')
print(... |
5970d98861d76f93c2d65e581cc1b25f403414cf | anantkaushik/Data-Structures-and-Algorithms | /Data-Structures/Linked-List/Singly-Linked-List.py | 1,529 | 3.828125 | 4 | """
------------------------ Singly Linked List -------------------------
"""
class node:
def __init__(self, data = None):
self.data = data
self.next = None
class singly_linked_list:
def __init__(self):
self.head = node()
def append(self, data):
new_node = node(data)
cur = self.head
while cur.next != N... |
9eb5f962bc60fa4c74d117fab1c7234562f1266d | anantkaushik/Data-Structures-and-Algorithms | /Data-Structures/Graphs/bfs.py | 1,458 | 4.125 | 4 | """
Graph traversal means visiting every vertex and edge exactly once in a well-defined order.
While using certain graph algorithms, you must ensure that each vertex of the graph is visited exactly once.
The order in which the vertices are visited are important and may depend upon the algorithm or question that
you ... |
f1b91c02185af877fa3df92eb314dc1de7ef58c9 | anantkaushik/Data-Structures-and-Algorithms | /Data-Structures/Linked-List/Doubly-Linked-List.py | 3,015 | 3.828125 | 4 | """
------------------------ Doubly Linked List -------------------------
"""
class Node:
def __init__(self, data = None):
self.data = data
self.next = None
self.prev = None
class doublyLinkedList:
def __init__(self):
self.head = None
self.tail = None
def length... |
97e987212668a8a076ba1c3f87dcea20c614d2c0 | ianpottinger/Python3 | /Python-Fractal-Art.py | 829 | 3.71875 | 4 | from turtle import *
shape("turtle")
speed(0)
def tree(size, levels, angle):
if levels == 0:
color("green")
dot(size)
color("black")
return
forward(size)
right(angle)
tree(size * 0.8, levels - 1, angle)
left(angle * 2)
tree(size * 0.8, levels - 1, angle)
right(angle)
backward(size)
def snowflak... |
3fa7c079c1b37f0cd751db5505fac7c7e00b6083 | ianpottinger/Python3 | /v3D_plutonicX_rotate.py | 2,446 | 3.515625 | 4 | import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import math
import random
# Define some colors
BLACK = (0, 0, 0)
WHITE = (1, 1, 1)
RED = (1, 0, 0)
GREEN = (0, 1, 0)
BLUE = (0, 0, 1)
# Initialize pygame
pygame.init()
# Set the width and height of the screen (in pixels)
SCREE... |
17fbdf5b9674a5545c7fb48924cd0f94cf9e3aa0 | ianpottinger/Python3 | /forex_currency.py | 1,218 | 3.65625 | 4 | from forex_python.converter import CurrencyRates
# Create a CurrencyRates object
c = CurrencyRates()
# Get a list of all available currencies
currencies = c.get_rates('GBP')
# Loop through all currencies and print the exchange rate against GBP
for currency, rate in currencies.items():
# Print the currency and th... |
9c8dd8c1dd5433494e3eddeb548bd40614f23e15 | sibrajas/objCandLinuxKernel | /objCandLinuxKernel/pyth/hello.py | 426 | 3.921875 | 4 | def fib(n):
print("hello world")
print 'Hell'
a,b = 0,1
while b<100:
print(a)
a,b = b,a+b
#print ("Last line")
#c = 0
#while c<10:
# print (c)
# c = c+1
#print("Again last line")
fib(5)
fib(5)
fib(5)
fib(5)
age = int(input("Enter your age"))
if age in range(15,20):
print("you are 15 to 20")
el... |
0a92515a2ba1f16a01d46db4147f8aee0967eb55 | dbzahariev/Python-and-Django | /Python-Basic/lec_3_Conditional_Statements/10_Toy_Shop.py | 837 | 3.53125 | 4 | price = dict(puzzle=2.60, speaking_Doll=3.0, teddy_Bear=4.1, minion=8.2, truck=2.0)
price_Excursion = float(input())
count = dict(puzzle=int(input()), speaking_Doll=int(input()), teddy_Bear=int(input()), minion=int(input()),
truck=int(input()))
total_sum = count["puzzle"] * price["puzzle"]
total_sum += c... |
05768cd1e169bd65c45b7752d10fa543624a70cf | dbzahariev/Python-and-Django | /Python-Basic/EXAM_1_dec_2018/solution/06_safe_passwords_generator.py | 533 | 3.734375 | 4 | a = int(input())
b = int(input())
max_combination = int(input())
symbol1 = 35
symbol2 = 64
count = 0
result = ''
for i in range(1, a + 1):
for j in range(1, b + 1):
result += f"{chr(symbol1)}{chr(symbol2)}{i}{j}{chr(symbol2)}{chr(symbol1)}|"
count += 1
symbol1 += 1
if symbol1 == 56:
... |
578558d13968aabad1110e7a9523b680c416ff92 | dbzahariev/Python-and-Django | /Python-Basic/ex_lec_6_for_loop/02_half_sum_element.py | 430 | 3.546875 | 4 | count_numbers = int(input())
sum_all = 0
max_number = 0
for i in range(0, count_numbers):
new_number = int(input())
if i == 0:
max_number = new_number
sum_all += new_number
if max_number < new_number:
max_number = new_number
if sum_all - max_number == max_number:
print('Yes')
pri... |
508b3d1c225f4cc2cca3639a050b9a814d99190a | dbzahariev/Python-and-Django | /Python-Basic/Ex_lec_2_simple_operations_and_calculations/01_2D_Rectangle_Area.py | 237 | 3.796875 | 4 | x1 = float(input())
y1 = float(input())
x2 = float(input())
y2 = float(input())
side_1 = max(x1, x2) - min(x1, x2)
side_2 = max(y1, y2) - min(y1, y2)
area = side_1 * side_2
perimeter = 2 * (side_2 + side_1)
print(area)
print(perimeter)
|
2964932bc4395158beb2ee0eba705ee180eaac84 | dbzahariev/Python-and-Django | /Python-Basic/exam_preparation_1/part_1/task_4.py | 539 | 4.1875 | 4 | best_player_name = ''
best_player_goal = -1
while True:
text = input()
if text == 'END':
break
player_name = text
player_goals = int(input())
if player_goals > best_player_goal:
best_player_name = player_name
best_player_goal = player_goals
if player_goals >= 10:
... |
a01c74fa956ddb63f20c70a6e402eaa49fd25b5d | dbzahariev/Python-and-Django | /Python-Basic/lec_6_for_loop/09_clever_lily.py | 377 | 3.5625 | 4 | year = int(input())
price = float(input())
toys_price = int(input())
sum_money = 0.0
for i in range(1, year + 1):
if i % 2 == 0:
sum_money += i * 5 - 1 # for year 8 add 40 lv and - 1 for brother
else:
sum_money += toys_price # add toys_price
diff = sum_money - price
if diff >= 0:
print(f"Y... |
4795fca952464ab3ada13df7bdfee75c26baa02b | dbzahariev/Python-and-Django | /Python-Basic/Ex_lec_2_simple_operations_and_calculations/06_Charity_Campaign.py | 555 | 3.875 | 4 | days_charity = int(input())
baker_count = int(input())
cake_count = int(input())
waffle_count = int(input())
pancake_count = int(input())
cake = 45
waffle = 5.80
pancake = 3.20
total_cake_price = cake_count * cake
total_waffle_price = waffle_count * waffle
total_pancake_price = pancake_count * pancake
total_money_day... |
5c05ae9b852ffc102d6ce76ecee01521dc4d0d94 | zipsa/ProjectHistory | /dna_string_algorithms-py/dna_frequency_mut.py | 2,651 | 3.96875 | 4 | '''
Approximate Pattern Matching Problem: Find all approximate occurrences of a pattern in a string.
Input: Strings Pattern and Text along with an integer d.
Output: All starting positions where Pattern appears as a substring of Text with at most d mismatches.
Sample Input:
ATTCTGGA
CGCCCGAATCCAGAACGCATTCCCATATTTCGG... |
8a428f5ecc931581304ef7cbc91113dcbeba4bfa | zipsa/ProjectHistory | /dna_string_algorithms-py/dna_location.py | 819 | 3.640625 | 4 | '''
Input: Two strings, Pattern and Genome.
Output: A collection of space-separated integers specifying all starting positions where Pattern appears
as a substring of Genome.
'''
def find_location (dna, pattern):
location = []
for i in range (0, len(dna) - len(pattern) + 1):
if dna[i : i + len(pattern... |
efa0e3bc5c57b4ce2b981fc8789043e61f6a5766 | Vinicius-Moraes20/personal-projects | /programming/python/ex008.py | 192 | 3.859375 | 4 | m = float(input("Digite a metragem a ser convertida: "))
cm = m * 100
mm = m * 1000
print("Metros: {}m".format(m))
print("Centimetros: {}cm".format(cm))
print("Milimetros: {}mm".format(mm))
|
6eadedf8522df051f41b244895ef32a747c2a06e | Vinicius-Moraes20/personal-projects | /programming/python/aula12/ex01.py | 323 | 4.21875 | 4 | nome = str(input("Digite seu nome: ")).strip().capitalize()
if (nome == 'Vinicius'):
print("Que nome bonito!")
elif (nome == 'Pedro' or nome == 'Maria' or nome == 'Paulo'):
print("Seu nome é bem popular no Brasil!")
elif (nome in 'Ana Claudia Jessica Juliana'):
print("Belo nome feminino!")
print("Tenha um bo... |
71e081c08f938846088fcf86a22f7a8d28547b2f | Vinicius-Moraes20/personal-projects | /programming/python/ex019.py | 351 | 3.71875 | 4 | import random
aluno1 = input("Digite o nome do primeiro aluno: ")
aluno2 = input("Digite o nome do segundo aluno: ")
aluno3 = input("Digite o nome do terceiro aluno: ")
aluno4 = input("Digite o nome do quarto aluno: ")
lista = [aluno1, aluno2, aluno3, aluno4]
sorteado = random.choice(lista)
print("O aluno() escolhid... |
4657ab67257c84b55db6b4aca816512b8cca7774 | Vinicius-Moraes20/personal-projects | /programming/python/ex047.py | 120 | 3.828125 | 4 | print("Numros pares de 0 a 50:")
for c in range(1, 51):
if (c % 2 == 0):
print(c, end=" ")
print("Acabou!") |
be68e36dca52277ac44319e15da56c61f319f267 | Vinicius-Moraes20/personal-projects | /programming/python/ex044.py | 740 | 4.125 | 4 | valCompras = float(input("Digite o valor total das compras: R$"))
print ("""---- Formas de pagamento ----
[1] à vista dinheiro/cheque
[2] à vista cartão
[3] 2x no cartão
[4] 3x ou mais no cartão""")
op = int(input("> "))
if op == 1:
valPagar = valCompras - (valCompras * 0.10)
elif op == 2:
valPagar = valCompra... |
010c2bef6dfdc144f3faac957f5a31e1e851c7b7 | Vinicius-Moraes20/personal-projects | /programming/python/aula10/ex02.py | 286 | 3.90625 | 4 | n1 = float(input("Digite a primeira nota: "))
n2 = float(input("Digite a segunda nota: "))
media = (n1 + n2) / 2
print("Sua média foi {:.1f}".format(media))
if (media <= 5) :
print("Reprovado!")
else:
print("Aprovado!")
#rint("Reprovado") if media <= 5 else print("Aprovado!") |
d135c5664f32e5133952cb43be29f0b594e722f1 | Vinicius-Moraes20/personal-projects | /programming/python/aula13/ex01.py | 82 | 3.578125 | 4 | i = 6
c = 6
for c in range(i, 0, -1):
print ("{}º Oi".format(c))
print("Fim") |
17518149ca3a7c1fa04490fff5a0cefc9ca8e0b5 | jonstaryuk/advent-of-code | /2017/day11.py | 653 | 3.59375 | 4 | from sys import stdin
def dist(x, y):
return (abs(x) + abs(y) + abs(x + y)) // 2
def solve(steps):
x, y = 0, 0
max_dist = 0
for step in steps:
if step == 'n':
y -= 1
elif step == 'ne':
y -= 1
x += 1
elif step == 'se':
x += 1
... |
ab309a9dea4850fde9a5717508eb6f23b7918ac7 | takuma2021/B4_Programming | /day2/task11.py | 597 | 3.921875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Apr 24 20:28:03 2021
@author: takum
"""
import numpy as np
class ReLU:
def __init__(self):
self.mask = None
def forward(self, x):
self.mask = (x <= 0)
out = x.copy()
out[self.mask] = 0
return out
def... |
e82a80ec2fd096cf40f941fb41443df50a37045a | kevindeangelesjr/cs50 | /python/notes/agree.py | 199 | 4.09375 | 4 | s = input("Do you agree?\n")
#if s == "Y" or s == "y":
if s.lower() in ["yes", "y"]:
print("Agreed.")
#elif s == "N" or s == "n":
elif s.lower() in ["no", "n", "nope"]:
print("Not agreed.") |
4743f6f710e89013d2d6d2a6ac41e31fd3294aaf | arikpar/CIS-1415 | /chapter7phoneNumber.py | 773 | 3.765625 | 4 | #Arik Parenteau
#Gabe Sorenson
phoneNumber = input('Enter a phone number in the form xxx-xxx-xxxx to translate:\n')
phoneNumber = phoneNumber.upper()
for i in phoneNumber:
if i in ['A','B','C']:
phoneNumber = phoneNumber.replace(i,'2')
elif i in ['D','E','F']:
phoneNumber = phoneNumber.replace(i,'3')
elif i in ... |
f9699fcb88090a087a916e35a5112b45b2143438 | arikpar/CIS-1415 | /chapter7initials.py | 258 | 4.09375 | 4 | #Arik Parenteau
#Gabe Sorenson
fullname = input('Enter a full name\n')
namelist = fullname.split()
initial1 = namelist[0][0].upper()
initial2 = namelist[1][0].upper()
initial3 = namelist[2][0].upper()
print('The initials are: %s. %s. %s' % (initial1,initial2,initial3))
|
b59b705ac1b986864f4ed993f3cdfe5e868dc00a | michebot/i-can-tell-that-you-been-practicing | /contains_all_items.py | 684 | 3.96875 | 4 | def contains_all_items(list1, list2):
if type(list1) == int:
list1 = [list1]
if type(list2) == int:
list2 = [list2]
elif list1 == [] or list2 == []:
return True
elif list1 == list2:
return True
list1_dict = dict()
list2_dict = dict()
for item in lis... |
7260c5bc6c62ec8395e56dc66f10c3858e1ae155 | cocodrips/python2-collection | /snakeCamel.py | 776 | 4.15625 | 4 | """
snake_case => camelCase
camelCase => snake_case
"""
def is_snake_case(word):
if "_" in word :
return True
return False
def translate(word):
new_word = ""
if is_snake_case(word):
is_next_upper = False
for c in word:
if c == "_":
is_next_upper = Tr... |
0adc5800f99519b907a6939fee2c38ebc950da38 | chaosWsF/Python-Practice | /leetcode/0326_power_of_three.py | 710 | 4.34375 | 4 | """
Given an integer, write a function to determine if it is a power of three.
Example 1:
Input: 27
Output: true
Example 2:
Input: 0
Output: false
Example 3:
Input: 9
Output: true
Example 4:
Input: 45
Output: false
Follow up:
Could you do it without using any loop / recursio... |
93bb133e04f6f9eb61e9cf2e12c91aca1a326e36 | chaosWsF/Python-Practice | /leetcode/0908_smallest_range_i.py | 710 | 3.765625 | 4 | """
Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and add x to A[i].
After this process, we have some array B. Return the smallest possible difference between the maximum value
of B and the minimum value of B.
Example 1:
Input: A = [1], K = 0
Output: 0
Explan... |
b123aacf1549581d2b000ad0970e28531c40e5ec | chaosWsF/Python-Practice | /leetcode/0029_divide_two_integers.py | 2,040 | 4 | 4 | """
Given two integers dividend and divisor, divide two integers without using
multiplication, division and mod operator.
Return the q after dividing dividend by divisor.
The integer division should truncate toward zero.
Example 1:
Input: dividend = 10, divisor = 3
Output: 3
Example 2:
Input: dividen... |
029b0f47951428b92e2eae989a912ae13660eed1 | chaosWsF/Python-Practice | /leetcode/0633_sum_of_square_numbers.py | 2,276 | 3.984375 | 4 | """
Given a non-negative integer c, your task is to decide whether there're two integers a and b
such that a ^ 2 + b ^ 2 = c.
Example 1:
Input: 5
Output: True
Explanation: 1 * 1 + 2 * 2 = 5
Example 2:
Input: 3
Output: False
"""
class Solution:
def judgeSquareSum1(self, c):
"""ide... |
96bb2abcca1ba8350ae913f04fc59cdebcaf1af2 | chaosWsF/Python-Practice | /leetcode/0205_isomorphic_strings.py | 1,881 | 4.09375 | 4 | """
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters.
No two characters may map to the same character but a character... |
51f673dd2d60b89320592cfb4f84a76ebb1f7acd | chaosWsF/Python-Practice | /leetcode/1089_duplicate_zeros.py | 937 | 3.96875 | 4 | """
Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right.
Note that elements beyond the length of the original array are not written.
Do the above modifications to the input array in place, do not return anything from your function.
Example 1:
... |
ba66e9707f75734abd0a2bfb61c9c74655f4ed62 | chaosWsF/Python-Practice | /leetcode/0035_search_insert_position.py | 1,291 | 4.15625 | 4 | """
Given a sorted array and a target value, return the index if
the target is found. If not, return the index where it would
be if it were inserted in order.
You may assume no duplicates in the array.
Example 1:
Input: [1,3,5,6], 5
Output: 2
Example 2:
Input: [1,3,5,6], 2
Output: 1
Example 3:
... |
272250aeb7a0799781c1775b90a8862092b462b6 | chaosWsF/Python-Practice | /leetcode/0771_jewels_and_stones.py | 742 | 4.0625 | 4 | """
You're given strings J representing the types of stones that are jewels, and S representing the stones you
have. Each character in S is a type of stone you have. You want to know how many of the stones you have are
also jewels. The letters in J are guaranteed distinct, and all characters in J and S are letters. L... |
922ff81151e11f40172f1e793d5a4ef585748a67 | chaosWsF/Python-Practice | /leetcode/0628_maximum_product_of_three_numbers.py | 1,350 | 4.03125 | 4 | """
Given an integer array, find three numbers whose product is maximum and output the maximum product.
Example 1:
Input: [1,2,3]
Output: 6
Example 2:
Input: [1,2,3,4]
Output: 24
Note:
1. The length of the given array will be in range [3,104] and all elements are in the range [-1000, 1000].
... |
eb0ea3e84e4e9585177ca3e312c3ecb40d8e89d4 | chaosWsF/Python-Practice | /leetcode/1009_complement_of_base_10_integer.py | 1,451 | 4.09375 | 4 | """
Every non-negative integer N has a binary representation. For example, 5 can be represented as "101" in
binary, 11 as "1011" in binary, and so on. Note that except for N = 0, there are no leading zeroes in any
binary representation. The complement of a binary representation is the number in binary you get when ch... |
6c9a0b00945ee3ea85cc7430ec2b40e660d05d4e | chaosWsF/Python-Practice | /leetcode/0532_k-diff_pairs_in_an_array.py | 1,281 | 4.1875 | 4 | """
Given an array of integers and an integer k, you need to find the number of unique k-diff
pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j
are both numbers in the array and their absolute difference is k.
Example 1:
Input: [3, 1, 4, 1, 5], k = 2
Output: 2
Ex... |
99b3a845267202d53a1f0e9e346b8bcb0a21a577 | chaosWsF/Python-Practice | /leetcode/0020_valid_parentheses.py | 1,707 | 4.1875 | 4 | """
Given a string containing just the characters
'(', ')', '{', '}', '[' and ']', determine if the input
string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Note that an empty string is also consider... |
ee5da787fc7206823a2f764e883ca3d3ecbf5caf | chaosWsF/Python-Practice | /leetcode/0344_reverse_string.py | 1,092 | 4.25 | 4 | """
Write a function that reverses a string. The input string is given as an array of characters char[].
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
You may assume all the characters consist of printable ascii characters.
Example 1:
... |
d6234976b95668e359303300c05f2be5f64b89d3 | chaosWsF/Python-Practice | /leetcode/0050_pow(x,n).py | 1,115 | 3.84375 | 4 | """
Implement pow(x, n), which calculates x raised to the power n.
Example 1:
Input: 2.00000, 10
Output: 1024.00000
Example 2:
Input: 2.10000, 3
Output: 9.26100
Example 3:
Input: 2.00000, -2
Output: 0.25000
Explanation: 2-2 = 1/22 = 1/4 = 0.25
Note:
1. -100.0 < x < 100.0
2. n ... |
c70a497fa0a9db39e3f4546fd96775912458e71d | chaosWsF/Python-Practice | /leetcode/0027_remove_element.py | 1,988 | 4.25 | 4 | """
Given an array nums and a value val, remove all instances of
that value in-place and return the new length.
Do not allocate extra space for another array, you must do this
by modifying the input array in-place with O(1) extra memory.
The order of elements can be changed. It doesn't matter what
you leave beyond... |
5b864a6612eef526b35e4361bb7338fc2a443997 | chaosWsF/Python-Practice | /leetcode/0350_intersection_of_two_arrays_ii.py | 1,648 | 4.03125 | 4 | """
Given two arrays, write a function to compute their intersection.
Example 1:
Input: nums1 = [1,2,2,1], nums2 = [2,2]
Output: [2,2]
Example 2:
Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output: [4,9]
Note:
Each element in the result should appear as many times as it shows in both arrays.
... |
ee269d8affa7ee9b3dc328ec04a90c3f823b31ba | chaosWsF/Python-Practice | /leetcode/0661_image_smoother.py | 1,956 | 3.875 | 4 | """
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to
make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 surrounding
cells and itself. If a cell has less than 8 surrounding cells, then use as many as you can.
Example 1:
... |
88c125859ecf7783defba104721a0ae975804954 | chaosWsF/Python-Practice | /leetcode/0793_preimage_size_of_factorial_zeroes_function.py | 971 | 4 | 4 | """
Let f(x) be the number of zeroes at the end of x!. (Recall that
x! = 1 * 2 * 3 * ... * x, and by convention, 0! = 1.)
For example, f(3) = 0 because 3! = 6 has no zeroes at the end,
while f(11) = 2 because 11! = 39916800 has 2 zeroes at the end.
Given K, find how many non-negative integers x have the property
t... |
94271589dae6e505801d42120a59e51dbcfc1dd5 | chaosWsF/Python-Practice | /leetcode/0914_x_of_a_kind_in_a_deck_of_cards.py | 1,112 | 4.03125 | 4 | """
In a deck of cards, each card has an integer written on it. Return true if and only if you can choose X >= 2 such that
it is possible to split the entire deck into 1 or more groups of cards, where:
1. Each group has exactly X cards.
2. All the cards in each group have the same integer.
Example 1:
I... |
940e8dd3aecbc31550306092037aaac0de5f5117 | chaosWsF/Python-Practice | /leetcode/0665_non_decreasing_array.py | 988 | 4 | 4 | """
Given an array nums with n integers, your task is to check if it could become non-decreasing
by modifying at most 1 element. We define an array is non-decreasing if nums[i] <= nums[i + 1]
holds for every i (0-based) such that (0 <= i <= n - 2).
Example 1:
Input: nums = [4,2,3]
Output: true
Explanati... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.